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.


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

  1. 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

  2. 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.

  3. 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

redirect double slash - two slashes in url - apache rewrite double slashes - apache double slash - apache redirect extra slash - htaccess remove slash - three slashes at the end of url - php add double slashes - php strip double slashes - mod_rewrite "google analytics" mobile - rewriterule double slash - .htaccess+double forward slashes - C# Remove double slash - remove trailing slash from url - remove double slashes - mod rewrite remove multiple trailing slashes - remove trailing slash from URI - C# remove double slashes - "google analytics" double slash - double slash at the end analytics - eliminate extra slash in url - htaccess how to remove /home from url - url double slash - .htaccess redirect double slash after url - multiple slashes in url - double slash in url problem "internet explorer" - error javascript remove double slash from url - extra slash apache rewrite - sex grabber de redirect - eliminate trailing slash from url - url extra slashes - htaccess slashes removed - mod_rewrite strip slashes -stripslashes - parse url multiple slashes php - redirect multiple directories apache - remove double slashes url php - remove extra trailing slashes - url redirect rewrite - mode rewrite replace characters - php mod rewrite remove extra slashes - redirect all requests to www double slash - rewrite double slash at the end - $_SERVER['REQUEST_URI'] double slashes - double slash apache redirect - htaccess replace characters in url - htaccess remove double slash - mod_rewrite remove multiple slashes - apache mod_rewrite replaces double slash - double slashes url causes IE6 access error - how to remove trailing slash from url -