title: Nginx & Handling Files Without Extension
body: <p>I'm trying to get Nginx to handle php files without an extension (i.e. to handle <a href="http://localhost/sample" rel="noreferrer">http://localhost/sample</a> the same way it would handle <a href="http://localhost/sample.php" rel="noreferrer">http://localhost/sample.php</a>).</p>
  
  <p>This is my site configuration:</p>
  
  <pre><code>server {
      listen 80 default_server;
      listen [::]:80 default_server ipv6only=on;
  
      server_name localhost;
  
      root /var/www;
      index index.html index.php;
  
      location ~ \.(hh|php)$ {
          fastcgi_keep_conn on;
          fastcgi_pass 127.0.0.1:9000;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          include fastcgi_params;
      }
  
      location / {
          try_files $uri $uri/ $uri.html @extensionless =404;
      }
  
      location @extensionless {
          rewrite ^(.*)$ $1.php last;
      }
  }
  </code></pre>
  
  <p>As far as I know it should do the trick. However - it doesn't. Trying <a href="http://localhost/sample" rel="noreferrer">http://localhost/sample</a> just gets me to a 404 page (whereas <a href="http://localhost/sample.php" rel="noreferrer">http://localhost/sample.php</a> works fine).</p>
  
  <p>When turning on debugging, I see the following in the logs:</p>
  
  <pre><code>2015/07/19 15:37:00 [debug] 4783#0: *1 http script var: "/sample"
  2015/07/19 15:37:00 [debug] 4783#0: *1 trying to use file: "/sample" "/var/www/sample"
  2015/07/19 15:37:00 [debug] 4783#0: *1 http script var: "/sample"
  2015/07/19 15:37:00 [debug] 4783#0: *1 trying to use dir: "/sample" "/var/www/sample"
  2015/07/19 15:37:00 [debug] 4783#0: *1 http script var: "/sample"
  2015/07/19 15:37:00 [debug] 4783#0: *1 http script copy: ".html"
  2015/07/19 15:37:00 [debug] 4783#0: *1 trying to use file: "/sample.html" "/var/www/sample.html"
  2015/07/19 15:37:00 [debug] 4783#0: *1 trying to use file: "@extensionless" "/var/www@extensionless"
  2015/07/19 15:37:00 [debug] 4783#0: *1 trying to use file: "=404" "/var/www=404"
  </code></pre>
  
  <p>Which is weird. It basically looks like @extensionless is treated as a plain filename (instead of a location leading to a rewrite of the URL).</p>
  
  <p>What am I missing? :)
  Thanks!</p>