Using Live Preview Across Multiple Subdomains

You must be running at least Craft 2.4.2726 for the technique recommended by this article to have any effect.

If your site has multiple locales whose base URLs span across multiple subdomains, you will need to make some special configuration changes in order to get Live Preview in cross-domain scenarios.

As an example, let’s say your site has two locales: English (located at mydomain.com), and German (located at de.mydomain.com). If you are accessing the Control Panel from mydomain.com/admin and edit an entry’s German translation, you will likely get a JavaScript error about a cross-domain security restriction if you try to open Live Preview.

To work around this, two changes must be made:

  1. Open up craft/config/general.php and set the defaultCookieDomain config setting to '.mydomain.com':

    'defaultCookieDomain' => '.mydomain.com',

    This will cause user session cookies generated by Craft to apply to all subdomains of your domain name, so user sessions can persist across them.

  2. Open up the .htaccess file in each of your public web-roots, and add the following code to them:

    Header set Access-Control-Allow-Origin "http://mydomain.com"
    Header set Access-Control-Allow-Credentials true

    On the first line, replace http://mydomain.com with the domain name you will be accessing the Control Panel with.

Once those changes have been made, you will need to either clear your browser’s cookies or restart the browser, so the new defaultCookieDomain config value can take effect.