title: Nginx: Using rewrite together with try_files
body: <p>I'm trying to use <code>rewrite</code> alongside <code>try_files</code>. Ideally, I would like Nginx to try the raw URI first. If that doesn't work, then try a controller <code>/controllers/$1.php</code>. Finally, just redirect to the index. This is what I have so far (I've sacrificed the ideal order mentioned above for succinctness):</p>
  
  <pre><code>location / {
    if (-f /controllers/$uri) {
      rewrite ^(.*)$ /controllers/$1.php last;
      return 403;
    }
    try_files $uri $uri/ /index.php;
  }
  </code></pre>
  
  <p>This doesn't seem to be working, though. Any ideas?</p>