4

我还想 301 重定向任何以.php. 然后我在内部将任何以 a 结尾的内容重定向到plus/之前的名称。当他们独自一人时,它们都可以正常工作。但是把它们放在同一个我得到一个./.php.htaccessThe page isn't redirecting properly

我在这里做错了什么?

RewriteRule ^(.*)\.php$ /$1/ [R=301,L]

RewriteRule ^(.*)/$ $1.php [QSA,L]
4

1 回答 1

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]
于 2013-10-25T20:40:19.597 回答