Redirect or Rewrite to Remove Double or Multiple Slashes (//) in URL
Google search engine spider or crawler Googlebot is one of the most advanced and finest content grabber that extracts most if not all of any data of the Internet and World Wide Web, regardless of whether such contents or web pages are intended for public visitors.
As such, some webmasters may notice that Google is crawling and indexing web pages which are not supposed to be existed in the first place. One such instance is incorrect and wrong URL link location, such as when double slash, triple slash or multiple forward slashes been formed as part of the URL as extra slash or slashes been appended or added to the web page URLs. For example, a page with URL of http://www.domain.com/index.php is also been crawled by Google as http://www.domain.com//index.php, or sometimes even http://www.domain.com///index.php.
The web crawl and spider indexing by Google can be tracked and traced in Apache or web server access logs. And these double slash, triple slash, quadruple or more slash URLs can show up in the Google search results, and potentially can cause duplicate content issue , and worse, penalty that makes the site vanishing from Google search results listing or been pushed into supplemental results with low ranking.
The reason for additional slashes in the URL is unknown, and seems like it only happens on Google search engne. One possibility is visitors or other websites type or put incorrect backlink (external link), which picked up by ultra-sensitive Googlebot or Mediapartners-Google (Google AdSense crawler which also contribute website indexing of Google Search). But one thing is for sure – when one page with wrongful double or a few adjacent slashes been indexed, entire web pages within the website may be prone to such error too.
To fix and resolve the double slash or multiple slash URLs issue is pretty simple. Simply create a mod_rewrite directive in .htaccess code or Apache httpd.conf configuration file to rewrite or redirect permanently (status 301) all URL found to be contained two or more adjacent or trailing slashes to its proper and valid URL with just a single slash (/) instead or // or /// or even //// or more within the URL address, create a .htaccess file in the root directory (normally public_html) for the website with the following URL rewriting and redirection directive (if .htaccess already exists, just add in the code on top).
# Remove multiple slashes anywhere in URL
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
The above redirection or URL rewrite method will parse the complete URL section on the part after the domain name, and will change each part of double slash to single slash (and thus able to handle more than 2 slashes in URL too). For administrators who want to more efficient rewrite command, use the following code, which can only be used on .htaccess file.
# Remove multiple slashes after domain
RewriteRule ^/(.*)$ http://www.domain.com/$1 [R=301,L]
Replace domain name accordingly.
Related Articles
- Add Trailing Slash to the End of the URL with .htaccess Rewrite Rules
- SEO Friendly Rewrite Method to Move Website URL From Subdirectory to Root Parent Folder
- Uninstall and Remove Multiple Database Instances of Microsoft SQL Server 2005
- Running Multiple Instances of Windows Live Messenger (WLM) Polygamy and Remove Banner Ads with MultiLive
- Redirect Blogger RSS Feed to FeedBurner for Detailed Statistics and Monetize Ads
- Remove and Uninstall or Disable ModSecurity (mod_security)
- Seeing Double Wall Clock
- Double Driver Backups and Restores Device Drivers in Simple Steps
- No Sex Interaction In Airbus A380 Double Bed Suites
- Redirect, Stream and Listen All Audio, Sound and Music from Windows Mobile 5 and 2003 Devices to Bluetooh Headset or Earpiece










































January 31st, 2009 20:02
Hi! Is there a way to remove a single slash in the end of the URL? for example, http://www.example.com/blog/ to http://www.example.com/blog
August 18th, 2008 03:00
I am sorry but this causes trouble with IE 8 web slicing by breaking it, and only works in the root directory.
All sub directory listings will get triple slashes and expose server side includes, from the new perl hacks available.
Warning:
If you use any password protected logins, do not include this in your htaccess mod rewrite.
July 29th, 2008 19:33
Thanks a lot, a friend ask me how to remove that and we find the solution here