Lukas B.
Lukas B.

Reputation: 23

Ajax url doesn't work if domain is entered with www at the beginning

I am not familiar at all with ajax, but I'm using a plugin at my website which uses ajax function to check if it is installed and populate it. The problem is the plugin works without problems if I enter a domain without www at the beginning like this: sevillalingerie.com (this is the website I got problems with). If I try to access it by typing www at the beginning it shows an alert error. Here's a script which I think is causing it:

$(document).ready(function() {
    $.ajax({
        url: 'index.php?route=module/aninews/chaeckIfModuleIsInstalled',
        //url: 'http://localhost/opencart_v1_5_4/test.php?route=ani',
        dataType: 'json',
        success: function(json) {
            if(json['aninews_response_msg']){
            $.ajax({
                url: 'index.php?route=module/aninews',
                dataType: 'html',
                success: function(html) {
                    $("#aninews").html(html);
                },
                error: function(xhr, ajaxOptions, thrownError) {
                    alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                }
            });

            }else{

                //alert("Module Aninew Is Creating Some Problem In Your Website");
            }
        },
        error: function(xhr, ajaxOptions, thrownError) {
            alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText + "tst");
        }
    });
});

Upvotes: 0

Views: 66

Answers (1)

Lukas B.
Lukas B.

Reputation: 23

Ok so after 3 hours of thinking how this could possibly be solved, I came up with this solution: I changed my config.php define('HTTP_SERVER') function to use www with a domain. And then i altered an .htaccess file with the following code, which always adds www at the beggining of a domain name:

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Upvotes: 1

Related Questions