title: nginx : rewrite rule to remove /index.html from the $request_uri
body: <p>I've seen a few ways to rewrite the <code>$request_uri</code> and add the <code>index.html</code> to it when that particular file exists in the file system, like so:</p>
  
  <pre><code>if (-f $request_filename/index.html) {
      rewrite (.*) $1/index.html break;
  }
  </code></pre>
  
  <p>but i was wondering if the opposite is achievable:</p>
  
  <p>i.e. when somebody requests <code>http://example.com/index.html</code>, they're redirected to <code>http://example.com</code></p>
  
  <p>Because the nginx regexp is perl compatible, i tried something like this:</p>
  
  <pre><code>if ( $request_uri ~* "index\.html$" ) {
      set $new_uri $request_uri ~* s/index\.html//
      rewrite $1 permanent;
  }
  </code></pre>
  
  <p>but it was mostly a guesswork, is there any good documentation describing the modrewrite for nginx ?</p>