我还希望301重定向任何以.php
结尾的网址。然后,我在内部将/
中以/
结尾的所有内容重定向到.php
加.htaccess
之前的名称。这些都是独一无二的。但是将它们放在同一个The page isn't redirecting properly
我得到RewriteRule ^(.*)\.php$ /$1/ [R=301,L]
RewriteRule ^(.*)/$ $1.php [QSA,L]
。
我在这里做错了什么?
{{1}}
答案 0 :(得分:5)
这些规则适合您:
RewriteEngine On
## Adding a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule . %{REQUEST_URI}/ [L,R=301]
## hide .php extension
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1/ [R=301,L,NE]
# To internally forward /dir/file/ to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]