Add to cart not working on opencart homepage

Posted by Flo on 08 May 2012

A very common problem that many users encounter is the Add to Cart sometimes not working on their site homepage.

The problem is related to the url of the store. A website can be accessed trough adress like: as well as

When you first install opencart, the base of the website is going to be written in config.php, but it can only be one: either or (depends on the adress you accessed the installation in the first place). So if you install your store by going to, then the base of your website in config.php will be So here is the origin of the problem, because if you then access your store via , the add to cart wont work on the homepage.

To fix this problem, you can make a redirect in htaccess from to or the other way around (depends on which case applies to you).

First, to make a redirect from non www to  www adress (ex: from to, edit the .htaccess from your opencart root and find the line:


RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]


and below it add the code:


RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*)$1 [R=301,L]


To make a redirect from www to non www adress (ex: from to, edit the same file mentioned above, and below the same line mentioned, add the code:


RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule (.*)$1 [R=301,L]


In both cases, replace with the adress of your store.