开发者

Nginx rewrite properly quoted ampersand in values causing problem

I开发者_如何学Go am trying to rewrite some urls with following nginx rewrite rule

rewrite ^/some\/url\/(.*)\/$ /some/url/?filter=$1;

Rewriting does not seem to work if a query contains an & e.g.

?filter=key:abcd & efgh

which I am quoting properly to

?filter=abcd%20%26%20N%20efgh

My problem is only rewritten url /som/url/key:abcd%20%26%20N%20efgh do not work. If I access it like /some/url/?filter=abcd%20%26%20N%20efgh it works fine.

Am I missing something?

Thanks.


Putting URL you want to rewrite to another "location" could solve your problem. (I suppose in location directive nginx doesn't do any escaping) So for your example it would be:

location /some/url/ {
 if ($uri ~* ^/some/url/(.*)$
 {
   rewrite ^.*$ /some/url/?filter=$1 break;
 }
 proxy_pass              http://127.0.0.1:8080;
 #proxy_set... <- and other proxy related things
}

at least it worked for me(in my case even question marks were replaced with "%3f". Excerpt from official documentation "Note that the $args variable is not decoded, unlike URIs during location matching." http://wiki.nginx.org/HttpRewriteModule


I noticed that I was using an old version of the nginx(7.6) and the problem was solved by upgrading to the latest stable release(1.0).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜