How do you determine when to use $request_uri
vs $uri
?
According to NGINX documentation, $request_uri
is the original request (for example, /foo/bar.php?arg=baz
includes arguments and can't be modified) but $uri
refers to the altered URI.
If the URI doesn't change, does $uri = $request_uri?
Would it be incorrect or better or worse to use:
map $uri $new_uri {
# do something
}
vs
map $request_uri $new_uri {
# do something
}
Another difference about
$uri
and$request_uri
inproxy_cache_key
is$request_uri
will includeanchor tags part
, but$uri$is_args$args
will ignore itDo a curl operation :
curl -I static.io/hello.htm?id=1#/favor/goods
:Nginx Document: http://nginx.org/en/docs/http/ngx_http_core_module.html#var_request_uri
$request_uri
: full original request URI (with arguments)$uri
: current URI in request, normalized The value of $uri may change during request processing, e.g. when doing internal redirects, or when using index files.Proxy Cache key: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_key
$uri
is not equivalent to$request_uri
.The
$uri
variable is set to the URI thatnginx
is currently processing - but it is also subject to normalisation, including:?
and query string/
characters are replace by a single/
The value of
$request_uri
is always the original URI and is not subject to any of the above normalisations.Most of the time you would use
$uri
, because it is normalised. Using$request_uri
in the wrong place can cause URL encoded characters to become doubly encoded.Use
$request_uri
in amap
directive, if you need to match the URI and its query string.