Sep 11, 2011
HobWebsAdmin

OpenCart | Canonical URLs

OpenCart

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 ‘www.example.com’ rather than ‘example.com 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} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

NOTES:
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.

Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy this password:

* Type or paste password here:

1,054 Spam Comments Blocked so far by Spam Free Wordpress

Donations

This site is a labour of love and it exists only through the kindness and generosity of visitors like you. We welcome and deeply appreciate your donation of any amount to help towards our running costs. You can securely make a donation using the PayPal button below. Thanks!



Sponsored Links

CodeCanyon
Photo Dune
Theme Forest
Graphic River