Remove multiple slashes anywhere in url using .htaccess

November 16, 08 by the programmer
Hello,
Sometimes a url can be accessed like this http://minanov.com//test.html.
The above url is the same as this one http://minanov.com/test.html, it points to the same content.
The search engines looks at this url as a duplicate content, which is not good and we have to eliminate it.
Sometimes urls with double slashes can be indexed by the search engines too. That is why a 301 redirect is added in the bellow code.
With 301 redirecting the url with double slashes to the url with single slashes we tell the search engine that the url is moved to the version with single slashes.
This is how to remove duplicate slashes from a url on a apache web servers using url rewriting and the .htaccess file.

 

Craete a .htaccess file in your root directory if you dont already have one.
Copy and paste the bellow code in the .htaccess file
Replace minanov.com with your domain name
Save the file and that’s it

 

#remove multiple slashes anywhere in url
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . http://minanov.com%1/%2 [R=301,L]

 

This entry no have comments... but you can be first.

Leave a Reply