下面是我当前的htaccess文件。它被设置为不允许扩展,301.php和.htm则不允许扩展。
我还需要添加尾部斜线,只要没有。这里有很多话题可以回答这个问题,但我似乎无法在不把其他事情搞砸的情况下添加它。
RewriteEngine On
# check to see if the request is for a PHP file and rewite to no extension:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}'.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
# redirect PHP or HTM to no extension
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}' /([^' ]+)'.(php|htm?)
RewriteRule ^ /%1 [L,R=301]
这样做:
RewriteEngine On
# redirect PHP or HTM to no extension
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}' /([^' ]+)'.(php|html?) [NC]
RewriteRule ^ /%1/ [L,R=301]
## Adding a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301]
# check to see if the request is for a PHP file and rewite to no extension:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}'.php -f
RewriteRule ^/?(.*)$ /$1.php [L]