I'm trying to write a simple rule such that:
/page
gets implicitly routed to /page.php
. Inversely, I'd like any direct access to /page.php
to be开发者_如何学Go redirected in the address bar to /page
.
Currently I have:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
But that does not handle the 2nd case. How can I modify it?
You have to treat your second rule before your first one. Try this:
RewriteEngine on
RewriteRule ^(.*)\.php$ http://domain.com/$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ $1.php
精彩评论