问题
maybe someone can help me with this problem. I want to remove the php extension. (i want to use grabaperch with nginx). This is the apache rewrite rule:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/$ $1.php [L]
Redirect 301 /portrait /portrait/zu-meiner-person.php
I use nginx 0.8.54 with php5-fpm on ubuntu 11.04.
URLs like this /folder/file.php should look like this /folder/file/ . URLs like this /folder/ should display the index.php
回答1:
After a lot of trial and error, i managed to end up to a working solution.Check below
try_files $uri $uri.php;
rewrite ^(.*)$ $uri.php;
Would be nice though if someone know how to add '/' in the end of the uri. Instead of example.com/products.php to become example.com/products/
来源:https://stackoverflow.com/questions/8970674/remove-php-file-extension-with-nginx-php-fpm