rewrite last using variable

Francis Daly francis at daoine.org
Mon Oct 28 08:09:38 UTC 2013


On Mon, Oct 28, 2013 at 01:56:16AM +0100, Ingo Schmidt wrote:

Hi there,

> set $var "/url?par=val";
> location = /b {
>     rewrite ^ $var last;
> }

> For location b the redirect is internal and now the backend cannot 
> process the request anymore.

> 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.

No; here what is sent to the client includes the bare ?.

> 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?

I believe it is intended to be "no", for internal rewrites at least.

You can do something like

    set $var "/url";
    set $vararg "par=val";
    rewrite ^ $var?$vararg last;

Although you may need to be more subtle if you know that your backend
handles "/url" and "/url?" differently, in case $vararg is empty.

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list