URL Canonicalization – Correct Your Home Page URLs

Many web sites on the Net suffer from duplicate pages because they contain the same home page extensions ie

http://domain.com
http://www.domain.com
http://domain.com/
http://www.domain.com/

This is called Canonicalization by Google.
It means you should use a consistent URL for the home page of your web site.


The problem

If you link some of your internal pages or external sites to http://domain.com and others to http://www.domain.com you’ll have duplicate pages all over the Web.
This will reduce the number of visitors to your site plus increase site loading times because the server has to load more pages.

What correct link structure should you use for your site?

You should always use a trailing slash when linking any internal pages or external pages to your home page.

ie the home page of your domain should end like this:

http://www.domain.com/

Why?

– If you ever had to switch to another coding language you would not have to change the directory URLs because they end with
the trailing slash ie news/.

– Adding a trailing slash to the directory URL will allow the browser to serve the correct file after a single request from the server.

– If you changed your site from pages ending in .html to pages ending in .php you would not have to change the directory structure.

– reduces site loading times.

What’s the solution?

Use a 301 redirect

If you’ve got mod_rewrite enabled on your server place this code in your .htaccess file:


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]

This will redirect the different types of home pages to:

http://www.domain.com/

If you need to redirect http://www.domain.com/index.html to http://www.domain.com/ place this code in your .htaccess file.


RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html?\ HTTP/ [NC]
RewriteRule ^(.*)index.html?$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]

Tip

If you have other pages that contain duplicate content within your site use the robots.txt file.

Resources

How to Redirect a Web Page Using a 301 Redirect

Trailing Slash – Creating Correct Link Structure

Include a Trailing Slash on Directory URLs

Trailing Slash – Use Proper URLs

URL Canonicalizaton

Comments

  1. Excellent article, such a small fix for a pretty big issue. This is the third article I’ve read at this site, it has some great info

    Keep up the good work =D

    Jordan

  2. This is a neat blog. Keep up the great work. Anyone ever tried House Flipping?

  3. Does that 301 above going from just / (no www) to the www. redirect in the browser as well?

    Because I uploaded the .htaccess file and typed in the website without a www in the browser and it just stays that way. It doesn’t refresh to the www address.

    The page re-direct works just fine from index.php to just / which also shows the redirect in the browser.

    Just wondering if that makes sense?

    THanks,
    Bob

  4. Have you contemplated incorporating a few movies on your URL Canonicalization – Correct Your Home Page URLs info? We feel this can augment some of our understanding great work Rgds Rob Rasner Facebook

Trackbacks

  1. […] more info about this, read here and here. __________________ […]

  2. […] you need to redirect all variations to a single URL version. That’s typically done with 301 redirects in .htaccess or sometimes with blog platform plugins. If this is too technical for you, […]

Speak Your Mind

*