我发现这个解决方案可以成功地将 url 从重定向www.domain.com/example.php
到,www.domain.com/example
但是当子目录很少时我不能做同样的事情,比如:domain.com/dir1/di2/dir3/example.php
todomain.com/dir1/di2/dir3/example
应如何修改此规则以使先前的重定向起作用?
RewriteRule (.*).php$ /$1 [R=301,L]
RewriteRule (.*).html$ /$1 [R=301,L]
这是我的 .htaccess
ErrorDocument 404 /misc/404.html
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule (.*).php$ /$1 [R=301,L]
RewriteRule (.*).html$ /$1 [R=301,L]
# Forces a trailing slash to be added
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
#RewriteRule (.*)$ /$1/ [R=301,L]
谢谢!