我目前的代码是从主文件夹中的所有目录中删除尾部斜杠:
DirectorySlash Off
#removing trailing slash
RewriteCond %{THE_REQUEST_FILENAME} \ /(.*)/(\ |$|\?)
RewriteRule ^(.*)/$ $1 [R=301,L]
# internally add the slash back
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ /$1/ [L]
如何添加现有代码以排除文件夹" myfolder"?
感谢您的帮助! :)
答案 0 :(得分:0)
您可以将规则设为:
DirectorySlash Off
RewriteEngine on
#removing trailing slash
RewriteCond %{THE_REQUEST_FILENAME} \s/+(.+?)/[\s?]
RewriteRule !^myfolder/$ /%1 [R=301,L]
# add trailing slash for myfilder
RewriteRule ^(myfolder)$ /$1/ [L,NC,R=301]
# internally add the slash back
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+?[^/])$ /$1/ [L]
答案 1 :(得分:0)
在RewriteEngine on
DirectorySlash Off
RewriteEngine on
DirectorySlash Off
#removing trailing slash
RewriteCond %{THE_REQUEST_FILENAME} \ /(.*)/(\ |$|\?)
RewriteRule ^(.*)/$ $1 [R=301,L]
# internally add the slash back
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ /$1/ [L]