1

Live preview is not working. The following error appears in Inspect Element (Safari). It then times out and generates a whole bunch of can't load errors. but this appears to the root of those subsequent errors.

XMLHttpRequest cannot load http://www.mydomain.com/index.php?p=posts/2016/thisost. Origin http://mydomain.com is not allowed by Access-Control-Allow-Origin.

I saw a related question that referred to the .htaccess file. But I can't seem to find the.htaccess file.

So, I guess this is an A and then B question. The first (A) being the focus and B only of import if its related to the solution for A.

I hope that makes sense. Thanks

1

A browser will give that error by default when you try make an AJAX call from domain A to domain B.

In your particular case, it looks like you're loading the control panel from mydomain.com, but the live preview request (which comes from how you defined your Site URL under Settings->General) has www.mydomain.com in it.

Note the www. A browser will treat that as an entirely separate domain.

If that's how you want it, great. You need to modify your public .htaccess file (the one that sits next to Craft's public index.php file to allow the other domain via Access-Control-Allow-Origin.

Likely it's just a mistake though and you should correct the Site URL setting or access the control panel from the other domain.

It's also worth forcing one or the other (www redirect to non, or non redirect to www) via .htaccess for consistency and because search engines will treat them as one site.

  • Per your suggestion, I added this to my .htaccess file ``RewriteCond %{HTTP_HOST} ^mydomain.com [NC] RewriteRule ^(.*)$ mydomain.com/$1 [L,R=301] – Hellyar Jan 5 '17 at 20:16
1

Also; in case this is part of your issue - the .htaccess file is a system file (starts with a dot) and will be hidden by default in your file browser. You either need to google how to show hidden files in your operating system, or open your project in an editor such as Visual Studio Code (free, cross platform) to see it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.