title: remove .php from url with rewrite rule
body: <p>I want to rewrite the url in nginx so that the <code>.php</code> extension can be omitted.</p>
  
  <p>This is what I have, but this isn't working for me. Anyone any idea how to do this?</p>
  
  <p>Thanks.</p>
  
  <pre><code>  server {
          listen 80;
          server_name example.com;
          return 301 $scheme://www.example.com$request_uri;       
  }
  
  server {
          listen   80;
          root /usr/share/nginx/www;
          index index.php;
          server_name www.example.com;
          error_page 404 http://www.example.com/404.php;
          autoindex off;
          error_log  /usr/share/nginx/www/nginx_error.log  warn;
  
     location / {
          rewrite ^(.*)$ /$1.php;
      }
  
      location = / {
          rewrite ^ /index.php;
      }
  
      location ~ \.php$ {
          include fastcgi_params;
          fastcgi_pass unix:/var/run/php5-fpm.sock;
      }
  
  }
  </code></pre>
  
  <p>this is my whole config file.</p>