Redirector - unescaping query parameters

Chris West lists at ruby-forum.com
Tue Feb 1 19:27:45 MSK 2011


I am trying to use nginx as a redirector that logs some data about the
request and then redirects the user to a user-specified URL.

This works well unless the user-specified URL contains query parameters.

For example, if this URL is requested:
http://my.site.com/redirect?p1=TEST&r=http%3A//www.new_site.com

I use this rewrite rule to redirect:

if ($arg_r ~* http.*) {
  rewrite ^(.*)$ $arg_r? redirect;
}


Any parameters in the user-specified URL are pre-escaped - notice that
the colon was replaced with %3A.

However, if the 'r' parameter that I redirect to also contains escaped
parameters, they do NOT get unescaped. For example, if the user requests
this URL:

http://my.site.com/redirect?p1=TEST&r=http%3A//my.site.jp%3Fparameter_1%3Dvalue_1%26parameter_2%3Dvalue_2

That is incorrectly rewritten as:
http://my.site.jp?parameter_1%3Dvalue_1%26parameter_2%3Dvalue_2

How can I instead redirect the user to:
http://my.site.jp?parameter_1=value_1&parameter_2=value_2


I do not know what parameters the user will be supplying in the
user-specified URL beforehand, so I can not extract them and rewrite
them manually. That is why they are encoded inside the 'r' parameter.

-- 
Posted via http://www.ruby-forum.com/.



More information about the nginx mailing list