rewrite last using variable

Ingo Schmidt lists at
Mon Oct 28 00:56:16 UTC 2013


consider the following simplified nginx config snippet:

set $var "/url?par=val";
location = /a {
     rewrite ^ $var redirect;
location = /b {
     rewrite ^ $var last;
location = /url {
     proxy_pass http://some_backend;

For location a the redirect goes via the client and everything works 
just fine.
For location b the redirect is internal and now the backend cannot 
process the request anymore.

I found out that it in the 2nd case the backend sees a URL encoded form 
of the contents of $var. So the question mark has become %3F and 
naturally the backend can't find the request parameters.
I guess that the URL encoding also takes place in the first case, but 
here the client decodes the URL and thus everything is ok again.

So here is my question:
Is it possible in nginx to make rewrites with variables where the 
variable contains a URL with parameters like in the example? If yes, 
what do I need to change? If no, what other options do I have?

Cheers, Ingo =;->

More information about the nginx mailing list