Forum Moderators: phranque
If I write
RewriteCond %{REQUEST_URI} ^/a$[NC]
RewriteRule ^(.*)$ http://www.example.com/ [L,R=301,NC]
then it removes the character "a" from http://www.example.com/a and it leaves the url as http://www.example.com. So far, so good.
But if you want to do the same with the slash instead of the character a then it does not work. Why is not working this next code?
RewriteCond %{REQUEST_URI} ^//$[NC]
RewriteRule ^(.*)$ http://www.example.com// [L,R=301,NC]
If http://www.example.com// is browsed, the second slash is not removed, why?
Thanks
# 301 redirect to remove multiple consecutive slashes in the middle or at the end of requested URL-path
RewriteRule ^(.+)//+(.*)$ http://www.example.com/$1/$2 [R=301,L]
# 301 redirect to remove multiple consecutive slashes at beginning of requested URL-path
RewriteRule ^/+(.*)$ http://www.example.com/$1 [R=301,L]
If this doesn't work, there's a more sophisticated version posted here that I can go dig up if you can't find it by searching.
Jim