您如何确定何时使用$request_uri和$uri?
How do you determine when to use $request_uri vs $uri?
根据NGINX文档,$request_uri是原始请求(例如,/foo/bar.php?arg=baz包含参数且不能修改),但是$uri指的是更改后的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.
如果URI不变,那么$ uri = $ request_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 }推荐答案
$uri不等同于$request_uri.
$uri变量被设置为nginx当前正在处理的URI -但也要进行标准化,包括:
The $uri variable is set to the URI that nginx is currently processing - but it is also subject to normalisation, including:
- 删除?和查询字符串
- 连续的/字符被单个/ 替换
- URL编码字符被解码
- Removal of the ? and query string
- Consecutive / characters are replace by a single /
- URL encoded characters are decoded
$request_uri的值始终是原始URI,并且不受上述任何规范化的约束.
The value of $request_uri is always the original URI and is not subject to any of the above normalisations.
大多数情况下,您会使用$uri,因为它已标准化.在错误的位置使用$request_uri可能导致URL编码的字符变得双重编码.
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.
如果需要匹配URI及其查询字符串,请在map指令中使用$request_uri.
Use $request_uri in a map directive, if you need to match the URI and its query string.
更多推荐
NGINX $ request
发布评论