query part included in location match after rewrite (bug or feature?)

aldem nginx-forum at nginx.us
Fri Sep 13 12:48:55 UTC 2013


Hi,

According to documentation, "location" matches only against URI path,
ignoring query string. However, after "rewrite", when using variables
containing "?" character (like $request_uri for illustration), query becomes
part of $uri:

location /src/ {
  rewrite  ^  /dst$request_uri;
}

location /dst/ {
  # At this point, $uri contains query part from /src, like
/dst/src/?arg=val
  add_header Content-Type text/plain;
  return 200 "$request_uri $uri $args";
}

For request like "/src/?arg=val" the output will be: /src/?arg=val
/dst/src/?arg=val arg=val 

Thus, $uri (and matched part) contains query, and $args *also* contains
query (inherited from original request). All together, this may lead to
quite unexpected results in some configurations.

So, my question is - is this expected behavior (just undocumented) or is a
bug? To me it looks like a bug - allowing matching anything past "?" in
location and making it part of $uri.

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,242829,242829#msg-242829



More information about the nginx mailing list