NGINX $request_uri vs $uri

后端 未结 2 1229
囚心锁ツ
囚心锁ツ 2021-01-31 08:03

How do you determine when to use $request_uri vs $uri?

According to NGINX documentation, $request_uri is the original request (for

2条回答
  •  余生分开走
    2021-01-31 08:32

    $uri is not equivalent to $request_uri.

    The $uri variable is set to the URI that nginx is currently processing - but it is also subject to normalisation, including:

    • Removal of the ? and query string
    • Consecutive / characters are replace by a single /
    • URL encoded characters are decoded

    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 a map directive, if you need to match the URI and its query string.

提交回复
热议问题