This is a recurring I have with my website: I can’t get my WordPress Network to work properly when using different, unrelated domains.

Both my personal and professional blog (blog.charliemerland.me and blog.caercam.org) from the same WordPress installation, as well as my Themes Demo site (themes.caercam.org). I read a lot about WordPress MU Domain Mapping, spend quite a lot of time reading StackExchange threads; I found a lot of answers, too, but nothing that would work for me. Here’s what I figured out.

Set up

I have three sites in my Network:

  • Blog | CaerCam.org
  • Blog | Charlie MERLAND
  • WordPress Themes

My Domain Mapping options are:

  1. ☑ Remote Login
  2. ☑ Permanent redirect (better for your blogger’s pagerank)
  3. ☐ User domain mapping page
  4. ☑Redirect administration pages to site’s original domain (remote login disabled if this redirect is disabled)
  5. ☑Disable primary domain check. Sites will not redirect to one domain name. May cause duplicate content issues.

And in wp-config.php:

define('WP_ALLOW_MULTISITE', true);
define('MULTISITE', true);
define('SUNRISE', 'on');
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'blog.caercam.org');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
define('NOBLOGREDIRECT', true);

No matter what changes I try to do, I either:

  • Lose control over at least one site, possibly all of them: « ERROR: Cookies are blocked or not supported » error
  • Cripple at least one site, possibly all of them: all permalinks redirect to the main site

The only I found to make things work is to alter mu /wp-content/sunrise.php file, commenting the Cookie related line:

if ( !defined( 'SUNRISE_LOADED' ) )
	define( 'SUNRISE_LOADED', 1 );

// Comment this
//if ( defined( 'COOKIE_DOMAIN' ) ) {
//	die( 'The constant "COOKIE_DOMAIN" is defined (probably in wp-config.php). Please remove or comment out that define() line.' );
//}

// let the site admin page catch the VHOST == 'no'
$wpdb->dmtable = $wpdb->base_prefix . 'domain_mapping';
$dm_domain = $wpdb->escape( $_SERVER[ 'HTTP_HOST' ] );

And add the following to wp-config.php:

define('WP_ALLOW_MULTISITE', true);
define('MULTISITE', true);
define('SUNRISE', 'on');
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'blog.caercam.org');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
define('NOBLOGREDIRECT', true);

$my_sites = array(
	'blog.caercam.org',
	'themes.caercam.org',
	'blog.charliemerland.me'
);

if ( isset( $_SERVER[ 'SERVER_NAME' ] ) && in_array( $_SERVER[ 'SERVER_NAME' ], $my_sites ) )
	define( 'COOKIE_DOMAIN', $_SERVER[ 'SERVER_NAME' ] );

Yes, that’s not a clean way to proceed, there might be a better solution (think of me when you find it!), but still, it works. This post is as much a reminder to myself in case I broke everything in a few months as it can be a piece of help for someone bumping into the same issue.

Photo: Cookies by Neil Conway

Publié par Charlie

Être humain depuis 1986, développeur web, designer et photographe, je code pour le Web depuis 2000 et pour WordPress depuis 2008. Aventure, Histoire, sciences, musique, café ou personnages forts en caractère et dotés d'un nez en tout point remarquable sont parmi mes passions les plus dévorantes. Indépendant depuis 2010 je travaille avec des gens formidables dans le monde entier, de la Californie à l'Europe en passant par l'Australie et l'Asie. D'autres détails croustillants ?

Rejoindre la conversation

4 commentaires

  1. Un très grand merci ! Ca fait des heures que j’écume le web à la recherche d’une solution, j’ai tout testé avant ça. Le plus bizarre étant que certains domaines fonctionnent bien et d’autres non (un en particulier).
    Cette solution marche parfaitement, merci pour le partage.

    1. Heureux d’avoir pu vous aider ! Cela fait quelques années que je n’ai pas touché à ce bricolage sur le présent site sans trop savoir si c’était toujours nécessaire, visiblement oui, donc tant mieux 🙂

  2. I had a related experience. For a few years I had been using the MU Domain Mapping plugin along with the sunrise setting in wp-config. But recently I had conflicts with this plugin and I learned that in version 4.5 and newer WP can do domain mapping inherently and so no plugin was needed.
    https://codex.wordpress.org/WordPress_Multisite_Domain_Mapping

    When I removed the plugin and edited the Sites, it all seemed to work, but when I created a new site I could not log into the admin site. What fixed it was commenting the sunrise statement out of wp-config.php and adding in the cookie statement you have listed.

    Now I can browse the front end and admin pages of all my sites and new ones work properly as well.

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée.

*