Hosting your website on multiple domain names can cause a duplicate content penalty. Many of us have variations of our domain names (such as domain.com and domain.co.uk or domain-name.com and domainname.com) so we need to let the search engines know which one is the primary (canonical) domain using 301 redirects via an apache rewrite rule.

We want to automatically 301 redirect all requests like:

http://domain.com/anything.html to http://www.domain.com/anything.html

AND

http://www.secondarydomain.com/anything.html to http://www.domain.com/anything.html

First you need to enable the rewrite engine (you may already have this line in your .htaccess file so double check before you add it):

RewriteEngine on

For a single domain we redirect any request that begins domain.com to www.domain.com

RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

If you only have one domain this is all you need to do.

For two or more domains follow this format:

RewriteCond %{HTTP_HOST} ^ primarydomain.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(.*)secondarydomain.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(.*)secondarydomain.co.uk [NC,OR]
#–> Carry on adding as many of these lines as you need

RewriteCond %{HTTP_HOST} ^(.*)secondarydomain.net [NC]
#—————–>> Note there is no OR on the last condition^^^

RewriteRule ^(.*)$ http://www.primarydomain.com/$1 [L,R=301]

It would also be wise to set the canonical URL in Google Webmaster tools.

We will post a guide on how to specify a canonical index page next week.

Google+

Comments

comments

This entry was posted in Blog. Bookmark the permalink.