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.


8 Responses to “Redirect or Rewrite to Remove Double or Multiple Slashes (//) in URL”

  1. Glen
    September 20th, 2009 02:25
    8

    Works like a charm. Was getting some 404 errors in my logs due to extra slashes from referring pages and this fixed it.

    Thanks!

  2. DaKorn
    September 1st, 2009 16:36
    7

    I think it would make more sense to use some RegExp in the RewriteCond.
    So you are not limited to two slashes, it can handle any number bigger than two.

    RewriteCond %{REQUEST_URI} ^(.*)/{2,}(.*)$

    Example: http://www,bla.de////bla///bla/index.html become http://www,bla.de/bla/bla/index.html

    bye dudes

  3. Mike
    August 4th, 2009 20:01
    6

    LOL
    I was looking for such an .htaccess rule too, and at the same time reading Tiger SEO’s blog.
    Funny to see him commenting there ^^

  4. Removing Double Slashes From URLs | Gary Harvey Blog
    July 22nd, 2009 12:13
    5

    [...] http://www.mydigitallife.info/2008/07/21/redirect-or-rewrite-to-remove-double-or-multiple-slashes-in... [...]

  5. Manish
    July 8th, 2009 16:05
    4

    Can any one tell me that how can i replace this double slashes to single slash in the following C# snippet.

    string Path=@”C:\\Temp\\ooops.bak”

  6. CountOcram
    January 31st, 2009 20:02
    3

    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

  7. jeffb
    August 18th, 2008 03:00
    2

    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.

  8. Tiger SEO
    July 29th, 2008 19:33
    1

    Thanks a lot, a friend ask me how to remove that and we find the solution here :)

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to comments feature has been disabled. To receive notification of latest comments posted, subscribe to My Digital Life Comments RSS feed or register to receive new comments in daily email digest.
Custom Search

New Articles

Incoming Search Terms for the Article

mod_rewrite double slash - double slash in url - apache double slash - apache rewrite double slash - RewriteRule double slash - htaccess remove slash - perl replace slash with double slash - remove slash htaccess - Apache2 path info multiple slashes - htaccess double slash - remove trailing slash c# - double content site URL with slash - double slash URL - URL multiple slashes - url rewriting double slash - what does double slash mean in google analytics - c# strings how to replace 2 slashes for one slash - c# 3.0 file move file double slash problem - remove double backslash httpd url rewrite - remove trailing slash from url - c# get string between slashes network name - perl replace multiple slash - rewrite remove www from adress htaccess - c# + remove double slashes - +perl convert double slash to single slash - .htaccess redirect removes last slash - triple front slash - "/"+pass slash to url - .htaccess redirect remove url end - apache warning double slash - c# string remove single slash from path - double slashes c# - htaccess rewrite url javascript - htaccess ending slash double slash removing - perl remove double slash - php remove double slashes - rewrite part of a url in htaccess - what do the two slashes in a url mean - .htaccess slashes in name - apache rules double slash - c# convert single slashes to double slashes path - C# remove slashes in path - C# remove last slash from directory path - c# double slashes in path file.exists - how to replace single slash by double slash in c# - htaccess rewrite double content - htaccess redirect slash - mod_rewrite apache2 remove end slash - multiple slashes valid url - php remove double slashed from url -