SEO – add trailing slash to URL

The problem

For those who use Google Webmaster Tool, they might find Google “duplicated content” warning. This is caused by slightly different URL, which is found by search engine.
Like:

and

are interpreted as 2 different pages by search engine. So how do we resolve this?

The solution

in htaccess (for Apache2 webserver) we create a simple redirect, which add trailing slash to the URL

Explenation

In line 1 we activate the rewrite engine, if this hasn’t been done yet. In the next line we check if the request URL is not requesting a file. Line 3 checks if there’s no trailing slash in the request URL. If so, then we rewrite it in line 4.

Happy rewriting!

2 thoughts on “SEO – add trailing slash to URL”

  1. Hi Ivan,
    thanks for your post about the problem with duplicate content.
    IMHO there is a slightly better alternative. In your example, domain.tld/google/ actually means domain.tld/google/index.php (or index.html, or index.htm, depending on the Apache configuration). Apache treats URLs with a trailing slash as directories (http://httpd.apache.org/docs/current/mod/mod_dir.html).

    When it comes to search results, Google probably ranks documents higher, when they are in a top level rather than deeply nested in a sublevel. The hierarchy might look like this:

    1. domain.tld/level1.html
    2. domain.tld/level1/index.html
    3. domain.tld/level1/level2.html
    4. domain.tld/level1/level2/index.html
    …and so on…

    With adding the slash at the end of the URL, you would end up in #2. If you add .html instead, you would be on level 1. For TYPO3 with the realurl extension this is trivial by using the “defaultToHTMLsuffixOnPrev” setting.

    Regards
    Jochen

    1. Hi Jochen,

      maybe I’m a bit unclear there. in some TYPO3 installation with realurl, sometimes you can load a page without trailing slash in the end. WordPress (like this blog) with it’s default settings, redirect automatically to URL with trailing slash.
      Yes, you are right with the “defaultToHTMLsuffixOnPrev” setting in realurl. But one may not like having “index.html” in the URL 🙂

      Ivan

Leave a Reply

Your email address will not be published. Required fields are marked *