Nginx Rewrite Paths to Base URL
<p>I am trying to configure Nginx so that all requests to <code>http://domain.com/path</code> are rewritten to <code>http://domain.com/</code>.</p>

<p>I do not want a redirect, because I want the URL to still show the original path.</p>

<p>Example Rewrites:</p>

<pre><code>http://domain.com/path/index.php         -&gt; http://domain.com/index.php
http://domain.com/path/category/books    -&gt; http://domain.com/category/books
http://domain.com/path/books.php?q=harry -&gt; http://domain.com/books.php?q=harry
</code></pre>

<p>I tried <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#alias" rel="noreferrer"><code>alias</code></a> and <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#root" rel="noreferrer"><code>root</code></a> but I could not get them to work.</p>

<pre><code>location /path
{
    root /var/www/html/;
}

location /path
{
    alias /var/www/html/;
}
</code></pre>