title: Simple nginx rewriting for clean urls
body: <p>I'm mostly using the standard nginx settings and rewrite using the following code:</p>
  
  <pre><code>rewrite ^/account/credit$ /account/credit.php$1 last;
  rewrite ^/account/credit\/$ //account/credit.php$1 last;
  </code></pre>
  
  <p>Basically, these two lines make sure that the following addresses are both recognized:</p>
  
  <pre><code>www.example.com/account/credit
  www.example.com/account/credit/
  </code></pre>
  
  <p>Is there a way to put this into one statement or do it more elegantly?</p>
  
  <p>I'm thinking about something like</p>
  
  <pre><code>rewrite ^/account/credit(\/)?$ /account/credit.php$1 last;
  </code></pre>
  
  <p>But this doesn't work because it looks at the wrong level when adding a / to the end of the address. Also the // looks a bit inelegant.</p>
  
  <p>This is what location looks like:</p>
  
  <pre><code>location / {
    try_files $uri $uri/ /index.php;
  }
  </code></pre>