Welcome! Log In Create A New Profile

Advanced

Redirector - unescaping query parameters

Chris West
February 01, 2011 11:32AM
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/.

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Redirector - unescaping query parameters

Chris West February 01, 2011 11:32AM

Re: Redirector - unescaping query parameters

Chris West February 04, 2011 04:38PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 166
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready