tags:

views:

76

answers:

2

When I open my site without "www", like http://mysite.com/, then there is a problem with my website hit counter on the home page, which is done through AJAX.

The problem is that counter Image is not getting displayed. It is showing blank. There are similar problem on other pages where I have used AJAX to retrieve data.

+6  A: 

To the cross-domain security policy, "mysite.com" and "www.mysite.com" are different domains, therefore AJAX requests aren't allowed between them.

The simplest solution is to take the domain out of your AJAX call and use a relative url, for example "/dir/ajax-callback.php" instead of "http://www.mysite.com/dir/ajax-callback.php"

Greg
http://en.wikipedia.org/wiki/Same_origin_policy
gnarf
thnx for reply. it works too.
+2  A: 

You can create .htaccess file in your root dir and put this text inside

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com [NC] 
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]

This will make sure that every time user enters http://mysite.com, it gets redirected to http://www.mysite.com

The server has to support .htaccess and mod_rewrite

michal kralik
it works. thnx.