[Virtuemart] Refused to set unsafe header "Connection"

While I was working on a Joomla 1.5.18, Virtuemart 1.1.4 website, I encounter this problem of "not able to add to cart" problem with Virtuemart.

When "Inspect Element" in Chrome, I got the following error
Refused to set unsafe header "Connection"
XMLHttpRequest cannot load http://www.example.com/index.php. Origin http://example.com is not allowed by Access-Control-Allow-Origin.

Apparently, after debugging for a while, I found out that for Ajax calls, example.com and www.example.com are considered different domain, thus the considered as unsafe "Connection"

Solution

The solution for this is pretty straight forward - make sure you are at the correct domain. To do this, create/add the following code in the .htaccess file in your public_html directory.
RewriteEngine on
RewriteCond %{http_host} ^example.com$ [nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc]
Note: Replace example.com with your domain.

That is by far the easiest way to solve this issue.

Comments

  1. you're my savior! Thank you very much! Just a clirification: the 2 rows are queued to the file! Else don't work! Thanks a lot

    ReplyDelete

Post a Comment

Popular posts from this blog

225019099301.apps.googleusercontent.com

Backup MySQL to Azure Storage in 30 Seconds

Generate GoDaddy SSL Certificate (.crt) for Azure Websites (.pfx)