URL encoding issue

Harish Sundararaj tuxtoti at gmail.com
Thu Apr 15 14:43:10 MSD 2010

Hi all,

I have a problem with nginx's urlencoding when it does a rewrite and passes
it on to a proxy backend. Below is the config:

location ~ ^/search/([^/]+)/?([^-/&]+)?.*$ {
  set $query $1;
  set $filter $2;

  rewrite ^ /search?q=$query&cat=$filter&$args? last;

location ~ ^/(search) {

                proxy_read_timeout 180;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_pass http://load_balance;

I match requests like :


and rewrite it to


which all works properly.

Now the problem is if the query has special characters like & , ", ' etc...
they are not urlencoded before rewriting:


/search/jhonson&jhonson  becomes  /search?q=jhonson&jhonson    but what I
expect is: /search?q=jhonson&26jhonson

/search/"tourism in paris" becomes /search?q=\"tourism%20in%20paris\"  but
what I expect is /search?q=%22tourism%20in%20paris%22  [This is weird spaces
are urlencoded properly]

Even if i try to urlencode it from the frontend(Javascript) like:

/search/jhonson&26jhonson still becomes /search?q=jhonson&jhonson  which
again looks weird to me !

Am i missing anything? Is there anything that i can do to get what i expect

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20100415/09fd7fa3/attachment.html>

More information about the nginx mailing list