rewrite last using variable

Francis Daly francis at daoine.org
Mon Oct 28 09:57:10 UTC 2013


On Mon, Oct 28, 2013 at 09:36:20AM +0100, Ingo Schmidt wrote:

Hi there,

I was (partly) wrong when I said

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

Reading the code, the string does go through some uri-escaping and some
uri-unescaping within nginx, and the end result is that a ? in $var
remains a ? in what is written to the client. But it's not a straight
copy of the string.

> >I believe it is intended to be "no", for internal rewrites at least.
> Hmm, any reason why it might be intended?

My guess? The value given must either be already uri-escaped, or not. And
nginx chooses "not".

> Also, it would be nice if the docs could mention this, because I find it 
> unintuitive, if rewrite behaves differently depending on the rewrite type.

If you presume that the docs are in the directory called "src", then
it's mentioned there ;-) Anything "redirect"ed goes through an unescape.

I expect that a correct clarifying patch to the docs will be welcomed,
if you fancy writing one.

> >You can do something like set $var "/url"; set $vararg "par=val"; 
> >rewrite ^ $var?$vararg last;
> Well, in my case that is exactly what I am trying to avoid, because my 
> variable is set in a map and I would have to create two maps then, one 
> with the URLs, the other with arguments.

Generally in nginx, if there's something that you can't do in config,
you can do it in a module you write. Possibly you can do it in config
using one of the scripting language modules.

(Usually, config is simpler in the short term.)

Good luck with it,

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list