Using Classic Live Preview Across Multiple Subdomains
This guide only applies to categories, as of Craft 3.2 and later. See Using Live Preview With An Alternate Control Panel Domain for previewing entries across multiple domains.
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:
Open
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.
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.