Canonical rewrite

16 January 2012
How should pages display canonical information?

Some search engines don’t like the difference between http://example.com and http://www.example.com. They see them as two different websites apparently. Google ‘canonical’ and you’ll see what I mean.

I’ve been searching for a resolution to this for a while now, and have only today come across the solution.

Until today, I’ve been adding the following meta tag:


As this seemed to satisfy the SEO Tools I’ve been using recently, I’ve been happily adding it to the header on my websites.

But today I came across a new SEO Tool website which still had problems choosing which version of the site was most important. Now I’m not saying the above meta tag is wrong – and it may be all you need. But in the long run the following solution is so much neater. It involves adding the following code within .htaccess on the server. (Sorry if you’re using anything other than a Unix type server!)

Options +FollowSymLinks
RewriteEngine on
RewriteCond % ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]
What it does is to rewrite the URL, adding www. to it. It’s beautiful. It works. I love it. And what I was looking for all the time.

 

blog comments powered by Disqus