remove multiple trailing slashes mod_rewrite
Posted
by Boyan
on Stack Overflow
See other posts from Stack Overflow
or by Boyan
Published on 2010-05-17T01:32:16Z
Indexed on
2010/05/17
2:40 UTC
Read the original article
Hit count: 346
I know this question was asked a number of times on this site alone, but browsing through the relevant posts I couldn't find a solution. Trying to remove multiple trailing slashes after domain. The following mod_rewrite expressions seem to work for URLs such as http://www.domain.com//path1///path2////, but do not work for domain//
DirectorySlash Off
RewriteEngine on
# Canonical fix
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301]
RewriteRule ^/main.do http://www.domain.com/ [R=301,L]
RewriteRule ^/index.jsp http://www.domain.com/ [R=301,L]
# Remove bogus query strings
RewriteCond %{query_string} q= [NC]
RewriteRule (.*) http://www.domain.com/$1? [R=301,L]
# Remove multiple slashes after domain - DOESN'T WORK!!!
#RewriteCond %{REQUEST_URI} ^//+(.*)$ [OR]
#RewriteCond %{REQUEST_URI} ^(.*/)/+$
#RewriteRule / http://www.domain.com/%1 [R=301,L]
# Remove multiple slashes anywhere in URL
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
# Externally redirect to get rid of trailing slash except for home page, ads
RewriteCond %{REQUEST_URI} !^/ads/
RewriteRule ^(.+)/$ $1 [R=301,L]
Your help is appreciated.
© Stack Overflow or respective owner