The canonical question: to www or not to www?

Since this was one of the first questions I asked myself while creating this website, I thought a little blogpost would help to explain you this important SEO issue. Canonicalization refers to the choice of choosing the best URL structure possible for your site. Should you use a www in your URL or not? I’ll refer to all my choices chronologically:

 

Should I use www in my URLs or not?

The short answer is: it doesn’t really matter! Some people will argue that it has become a standard on the internet to use www in your URLs, others will say that it is useless and should therefore be avoided. Personally I think it doesn’t matter! What matters is to make a choice since the very start and to stick to it! I chose to go for the version without www simply because my domain name is already quite long so I wanted to avoid too long URLs appearing in search results. So my preferred domain is http://picturesfromearth.com

 

301 redirects to your preferred domain.

So why is it so important to choose a preferred domain and to stick to it? For search engines the two versions of the URL will be considered as different. So to avoid confusing search engines with different versions that it would consider as duplicate, it is better to stick to just one. Start this good habit since the beginning in the way you link internally to your site and always use the same version. Unfortunately, you can’t force other people to link to you to the right version. Some will probably use the www version or the non-www version even though you never do. It is to avoid diluting or losing these links that it is wise to make a 301 redirect to your preferred domain version. You can achieve this very easily through the .htaccess file on the root of your server.

 

.htaccess 301 redirect.

To create a 301 redirect to your preferred domain, add it to your .htaccess file on the root of your site (or create a file that you name .htaccess and place it to the root of your site on your server). The code will vary according to the preferred domain you chose:

If your preferred domain is the non-www version ( you want to redirect www to non-www version):

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]

Replace “domain” with your domain name.

If your preferred domain is the www version ( you then want to redirect non-www to www):

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^(.*)\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

 

What if I have subdomains?

The code will cause problems if you have subdomains so you need to exclude them from the above code. I had the problem for my blog.picturesfromearth.com which was causing errors. To avoid this, simply add this code above the RewriteCond (and under “RewriteBase /”):
# Stop mod_rewrite processing if “example” subdomain requested
RewriteCond %{HTTP_HOST} ^example\.domain\.com
RewriteRule .* - [L]

There you go! This should not have taken you very long to implement but it will prove very valuable for you in the future!

This entry was written by Francois , posted on Monday March 09 2009 , filed under Webmaster tips and tagged , , , , ,

Leave a Reply

TopOfBlogs