I’m aware of this question and others but have not found a definitive answer to how a domain should be set up with multisite so that www and non-www variants behave correctly. I believe I have wildcards set up correctly at the DNS level and the suggested solution to add
define( 'NOBLOGREDIRECT', 'http://www.example.com' ); works for my main site but not other networks in the same install.
I am using the ‘WP Multi Network’ plugin based on some research which led me to the conclusion that if I am running several domains on one WordPress install, I should be using multiple networks, not just multisite. My Networks and sites are all added with
www included in the domain field
So what is the correct way to map bare domains without
www to a multisite install? Are plugins required? Should this all be handled in web server config using rewrites?
WordPress Multisite can handle different domains by default – but NOT with alias domains. The settings of each site store the domain. On a default install there is a subdomain or folder-structure. But you can add a single domain.
For example, the first two sites are with the same domain (default from install) and the third site working with a different domain, external from the default. The last one is a different domain. No plugins or custom source for domain mapping are required.
Here’s a the screenshot of the settings of the last site with a separate domain:
If you want to reduce the cookie check for each login, add the following constant to
define( 'COOKIE_DOMAIN', '' );
Otherwise WordPress will always set it to your network’s
$current_site->domain, which could cause issues in some situations.
Domain Mapping with Alias
If you require deeper customisation, such as mapping aliases to domains, plugins can help you. WordPress Core hopes to provide Domain Alias Mapping in the future, but until then you can make use of one of the following plugins:
- Mercator – WordPress multisite domain mapping for the modern era.
- WordPress MU Domain Mapping – Map any blog/site on a WordPressMU or
WordPress 3.X network to an external domain.
WWW vs Non-WWW
I don’t have the requisite knowhow about doing this with Non-WWW and WWW urls, but I think this case is slightly different. A domain like www.test.com has the subdomain www. But the www is a synonym for the web and often not interpreted as a subdomain. For all my clients, I rewrite to Non-WWW from the WWW address.
Hint for Creation of a new site
On the process, to create a new site it is not possible to add a external domain in the input field. Add an random value and after creation of the site, use the edit possibility to add the external site.