2

I'm upgrading my website and it's using WordPress. I'm using sub-domain cdn for CDN and it needs to be cookieless.

Currently my website is a multi-network of multisites (both are subdirectory installs), with the subdomain www hosting my main music project, and subdomain photo hosting my photography project.

The plugin I'm using for that kind of multi-network is: https://github.com/stuttter/wp-multi-network

I need to use Single Sign-on. And this leads me to a confusion while setting COOKIE_DOMAIN in wp-config.php. I can set like the plugin's documentation said:

define( 'COOKIE_DOMAIN',     'mydomain.com'        );

but I know this would make cookies served from cdn.mydomain.com.

How can I set COOKIE_DOMAIN in order to serve cookies from only two subdomains www and photo?

Or do I have to use another domain name just for CDN?

  • Is cdn.mydomain.com on of the sites in your WordPress Network? – David Jan 19 '16 at 23:14
  • No. cdn.mydomain.com is hosted on another server (Google App Engine). – LQ2' Jan 20 '16 at 4:15
  • So then this sentence is confusing: »but I know this would make cookies served from cdn.mydomain.com«. Why should a constant in your WP config affect other hosts? – David Jan 20 '16 at 9:38
  • Thank you! I've just tested my site using YSlow on GTmetrix. My CDN is cookie-free with that setting. – LQ2' Jan 20 '16 at 14:18
3

As cdn.mydomain.com is not part of your WordPress network, it wont be affected by your settings.

The COOKIE_DOMAIN constant should only be used if you want to serve cookies from a single domain for all your sites in the network. If you omit the constant or set it to an empty value, cookies will belong to the domain their requested from. Thats the configuration you want to use for multisite/network environments especially when it comes to different domains.

5

I have been struggling with using the multisite domains of native 4.x wordpress.

Despite finding references, saying these lines corrected the error, neither of these setting worked:

//define('COOKIE_DOMAIN', false);
//define( ‘COOKIE_DOMAIN’, $_SERVER[ ‘HTTP_HOST’ ] );

In the end, I added the following lines of code instead, and it worked marvellously...

define('ADMIN_COOKIE_PATH', '/');
define('COOKIE_DOMAIN', '');
define('COOKIEPATH', '');
define('SITECOOKIEPATH', '');

Not sure if this will be good for you?

  • I'm posting this mainly for future searchers who are having troubles.
  • 1
    This broke my site entirely – Adal Jan 30 '18 at 2:16
  • if it broke you're site then simply remove the code, and relogin setting the original values. This simply sets the cookie values, it doesn't affect database ETC. Note: my site runs on the root directory (domain.com/) so if you're in a sub directory (domain.com/wordpress) then you'd have to set cookiepath as /wordpress/ - – Wayne Brian Pearsall Jan 31 '18 at 21:47
  • Hey Wayne, that's the first thing I did. However, neither removing those definitions nor setting them to any other value was able to get the sites to work again. I had limited luck using a sunrise.php... but was never able to log in. I am on Google Cloud VM. I ended up restoring a disk snapshot and abandoning hope that native WPMU domain mapping can work. I'm back to using plugins. – Adal Feb 1 '18 at 22:44

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.