Canonical URLs in OpenCart

Posted by Paul on February 21, 2014

If you've looked in to SEO on any level you'll probably have heard of canonical URLs. So we'll try and answer a few questions about them.

Why such a funny name?
The canonical URL means the 1 URL of a certain website or page or a website that is considered the definitive one to use. It comes from the the word "canon" that means the one definitive set of rules or principles: http://en.wikipedia.org/wiki/Canon_(basic_principle)

How can a page have more than one URL?
For example it may be possible to access your home page via all 4 of these different URLS:

  1. www.yoursite.com
  2. yoursite.com
  3. www.yoursite.com/index.php
  4. yoursite.com/index.php

Isn't that duplicate content?
It is duplicate content and although Google is smart enough to realize it's not plagiarism if it's on the same website, Google must still decide which link to use in search results. It's better if you are the one who decides this.

What can I do to prevent this?
The good news is that OpenCart will already hide most of the /index.php style duplicate links (although we show you how to remove one they missed in this article).
But it may still be possible to  access your site via yoursite.com and www.yoursite.com. So you'll need to change it to always redirect to one or the other. It's personal preference which you go for and if you have already purchased an SSL certificate you'll have to stick with what's on there. If you have the choice I'd go for the one with www because it's more familiar to most users.

How do I configure my website to redrirect non-www requests to www?
If you've got FTP access to your site you'll need to make sure that the www is included in the links in /config.php and /admin/config.php. That way you'll be half way there - when people navigate your site they'll be redirected but not until they click a link. To redirect everyone, if they have a bookmark or if they've come from a link on an external site for example, you'll need to add a line to your .htaccess file. Again you'll need FTP access so ask your web developer about this if you don't have it. The line to add (modified for your domain of course) is:

RewriteCond %{HTTP_HOST} ^yoursite.com$
RewriteRule ^(.*)$ "https\:\/\/www\.yoursite\.com\/$1" [R=301,L]

Adding it at the very bottom should be fine in most cases.

Is it that easy?
Essentially yes, but always be very careful when modifying config files or .htaccess. A small typo could stop your site from loading so always be sure you know exactly how it was before by taking a copy so that you can put it back if it doesn't work.

How much will this effect my SEO?
Quite a bit. Enough for Matt Cutts from Google to write an article about it. It will also make browsing a nice experience for your customers as they'll always see a pretty, consistent URL.

blog comments powered by Disqus