# Understanding nginx $request_uri

Link: [https://stackoverflow.com/questions/48708361/nginx-request-uri-vs-uri](https://stackoverflow.com/questions/48708361/nginx-request-uri-vs-uri)

<div class="blog-header-section-main-div" id="bkmrk-as-we-came-across-th" style="text-align: justify;"><div class="section-blog-single"><div class="section-blog-item"><article class="section-blog-article">As we came across this question often ourselves, I decided to write a quick article about the *$request\_uri* handling of nginx. According to the ngx\_http\_core\_module-documentation, the variable *$request\_uri* is defined as:

```
full original request URI (with arguments)
```

While this seems clear at first, it is not well defined. We have done some trial and error and can best explain it by examples using real cases:

<div class="section-blog-content">1. For the URL:  
    [https://www.webhosting24.com/understanding-nginx-request\_uri/](https://www.webhosting24.com/understanding-nginx-request_uri/)  
    the nginx variable $request\_uri is populated as follows:  
    **/understanding-nginx-request\_uri/**
2. For the URL:  
    [https://www.webhosting24.com/cp/cart.php?a=add&amp;domain=register](https://www.webhosting24.com/cp/cart.php?a=add&domain=register)  
    the nginx variable $request\_uri is populated as follows:  
    **/cp/cart.php?a=add&amp;domain=register**
3. For the URL:  
    https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.2  
    the nginx variable $request\_uri would still be populated only as follows:  
    **/Protocols/rfc2616/rfc2616-sec3.html** as #sec3.2 is just a fragment/comment/anchor and not part of the URI.

</div>Simply put, the *$request\_uri* contains the full path (/understanding-nginx-request\_uri/ in example 1 or /cp/cart.php in example 2 above) and any argument strings that may be present (“?a=add&amp;domain=register” in example 2 above), but excludes the schema (https:// and the port (implicit 443) in both examples above) as defined by RFC for the URL:

```
http_URL = "http(s):" "//" host [ ":" port ] [ abs_path [ "?" query ]]
```

## Uniform Resource Identifiers

By RFC URIs have been known by many names: WWW addresses, Universal Document Identifiers, Universal Resource Identifiers, and finally the combination of Uniform Resource Locators (URL). As far as HTTP is concerned, Uniform Resource Identifiers are simply formatted strings which identify–via name, location, or any other characteristic–a resource.

Further Sources:  
[https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.2](https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.2)  
[http://nginx.org/en/docs/http/ngx\_http\_core\_module.html#var\_request\_uri](http://nginx.org/en/docs/http/ngx_http_core_module.html#var_request_uri)

</article></div></div></div><div class="comment_box" id="bkmrk-"><div id="bkmrk--1"></div></div>