OpenCart | Canonical URLs


*UPDATE – We ditched OpenCart and are about to try Prestashop. This is not a reflection on OpenCart but the client needs a solution that will sync between their Amazon and Ebay shops.

We recently decided to setup an OpenCart store for one of our clients. This comes after years of using CubeCart as an off-the-shelf shopping cart solution for various other clients. For various reasons that I won’t go into here, we decided to go with OpenCart instead.

One of the things I like to do with any site is to make sure we are using Canonical URLs.
For those who don’t know what I’m talking about, here is a quick description:

Canonicalization is the process of picking the best url when there are several choices, and it usually refers to home pages . *

For example, I like my URL to be in the format ‘’ rather than ‘ so I use Apache’s MOD REWRITE function to make it change automatically when someone types in the URL without the ‘www’.
This can be helpful for Search Engine Optimisation amongst other reasons. More info at the end of the post.

Anyway, let’s have a look at our .htaccess file for OpenCart to see how we achieve this.

Here is the complete section for URL rewrites (for SEO URLs and Canonical URLs) in the  .htaccess file. This is working with OpenCart 1.5.1

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not reside in the root web folder make sure you change the folder it does run in i.e. / becomes /shop/

# RewriteBase /
RewriteCond %{HTTP_HOST} ^
RewriteRule (.*)$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

This rewrite first takes a URL without the ‘WWW’ and rewrites it to include the ‘WWW’. The last three lines above are those that are included with the default OpenCart install to rewrite the ends of the URLs so they are more SEO friendly.
I commented out the RewriteBase because SEO URLS didn’t work with it on.
The order of the above entries DOES make a difference.
If you have problems logging into your ADMIN dashboard after doing this, make sure your URLs are correct in the two config.php files, one located in the root of the store and the other in the admin directory.

The above configuration may not work for your server if it is set up differently. Please don’t ask me how to make your broken .htaccess file work. I don’t know. There are many resources about MOD REWRITES on the web – Google is your friend.

* Quote from Matt Cutts’ blog. For more information about canonical URLs and how they can help SEO please visit Matt Cutts’ page about it here.