简体   繁体   English

如果没有,则htaccess添加尾部斜杠

[英]htaccess add trailing slash if there isn't one

Below is my current htaccess file. 下面是我目前的htaccess文件。 It's set up to allow for no extensions and to 301.php and .htm to no extension. 它设置为不允许扩展,301.php和.htm不允许扩展。

I also need to add trailing slashes whenever there isn't one. 我还需要在没有斜杠的情况下添加尾部斜杠。 There are plenty of topics on here answering that question but I can't seem to add it without messing something else up. 这里有很多主题来回答这个问题,但我似乎无法添加它而不会弄乱别的东西。

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]

Have it this way: 这样做:

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM