I have this htaccess:
RewriteEngine On
# redirect with www
RewriteCond %{HTTP_HOST} ^mydomain [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1/ [R=301,L]
# add .php internally
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
So my .php files can be called without the .php extension.
But I'd like them to be called only with a trailing slash. So when this trailing slash is not given, 开发者_StackOverflow社区it should be appended with a 301. The problem I have is that this is giving me problems with the initial www, and the .php extension itself (sometimes it is adding recursively .php).
How can it be done?
Thanks!
I think you need to add something like this before your last rewrite rule, to avoid rewriting URIs that already end in .php
RewriteCond %{REQUEST_URI} !\.php$
精彩评论