Websites that can be accessed from multiple URL’s aren’t very search engine friendly.
Sometimes this structure may have evolved by accident as a site was developed at different times on varying technologies. You don’t want to turn off the old links as that would loose valuable search engine equity, but you don’t want them scattered on multiple URL’s either.
There is a solution, and that is to use a canonical URL.
The easiest is to add a simple link element to the page with it’s correct canonical URL. For example, if we have a page that can be reached at www.example.com/test.html
, example.com/test.html
or beta.example.com/test.html
. we only want this to be index at www.example.com/test.html
, so we can use add a link element as follows…
<link rel="canonical" href="http://www.example.com/test.html" />
Notice the use of rel="canonical"
, this is tells a search engine if it has accessed the page from another URL, it’s actually meant to be indexed from this URL.
Google, Yahoo and Microsoft have all agreed to support this canonical link element.
Another approach is to redirect the user to the page on the correct URL server side. Using Apache, this can be done using a RewriteRule
and couple of RewriteCond
‘s.
Using the same example, the rewrite rule would be something like this
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.example.com/$1 [L,R=301]
Here we make sure we’re not already accessing using the correct domain name. If we aren’t, the we redirect using the L flag to make sure this it’s the last rule run, and R=301 to issue a 301 Moved Permenantly redirect. Anyone visiting the page on an incorrect domain, will now be redirected to the right page.