htaccess - Remove trailing forward slash except for
I have the following in htaccess to remove trailing slashes:
#RewriteCond %{HTTP_HOST} !^\.example\.com$ [NC]
#RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=3开发者_Go百科01,L]
This works great, but I now need to add an exception to that rule. I have a folder (lets call it 'myfolder') that needs a trailing slash. Is it possible to ammend the above condition to allow this?
Sure, like this, for example:
RewriteCond %{HTTP_HOST} !^\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/myfolder/$
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
This will exclude http://example.com/myfolder/
from being redirected to http://example.com/myfolder
. If myfolder
is located in a subfolder then you need to alter the path in rewrite condition accordingly.
If you want to exclude myfolder
regardless of where it is located (e.g. /myfolder/
, /something/myfolder/
or /something/interesting/myfolder/
) then alter rewrite condition accordingly:
RewriteCond %{HTTP_HOST} !^\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !/myfolder/$
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
精彩评论