Wordpress - How to use Wordpress Multisite With Different Domain Names?
There seems to always be a bit on confusion on this topic. Perhaps WordPress could do a better job guiding it's users in this process. Although, I suppose Multi-site wasn't intended to be used for TLD's.
So first of all, I would install WordPress, setup multisite, and configure it as a subdomain network configuration.
Here's a sample configuration for your wp-config.php
file in the base directory of your WordPress installation:
/* Multisite */
define( 'WP_ALLOW_MULTISITE', true );
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', true );
define( 'DOMAIN_CURRENT_SITE', 'www.primary-domain.com' );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );
Then, here's the basic configuration for your .htaccess
file as a subdomain configuration, in the base directory of your WordPress installation:
# BoF WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
# EoF WordPress
Now in order to get TLD's to work properly, I've had to make some additional configurations to the wp-config.php
file like this:
define( 'COOKIE_DOMAIN', '' );
define( 'ADMIN_COOKIE_PATH', '/' );
define( 'COOKIEPATH', '/' );
define( 'SITECOOKIEPATH', '/' );
That's it with the WordPress specific configurations.
Personally, I like to have one Apache Virtual Host for the primary domain in the network and then configure that virtual host with alias domains. Each alias domain being one of the additional sites in your network.
However you end up tweaking your setup, you need each domain's DNS to resolve to the same web server, and each domain to be pointed to the same directory the primary domain is installed with WordPress. Each domain in your network needs to point to the same web server with DNS records and share the same directory path for the files used by WordPress.
Once you've got everything configured and setup properly as discussed above. Log into your WordPress administration area and navigate to the Network administration area to add a new site into your network.
When you go to add a site, it will enforce you to add the website as if it were a sub domain under your primary domain. Just roll with it. Enter something temporary.
Once the site has been added, then go find it under the list of sites in your network. Click edit on that specific site. Now, you can fully 100% change the domain name of that website. That's when you would put the actual domain name for this TLD site.
I know it's a bit of trickery to do it that way, but it works and you don't need to use any plugins.
It is possible without any plugin since some releases ago (can't remember the concrete release but the feature has been there for a while now). However, if you start from scratch, you should install WordPress multisite in the subdomain mode.
You have to declare a main URL (probably kevin123.com
) as the main URL for the network (multisite). This is stored in wp-config.php
in the DOMAIN_CURRENT_SITE
constant and the site (formerly known as »blog«) using this domain as home URL must have the ID stored in BLOG_ID_CURRENT_SITE
. But this is pretty much default stuff during the standard installation process.
WordPress allows you only to specify the sub-domain, when you create a new site. But after the site is created you can edit it and add a completely arbitrary value for the site URL. I described it some time ago in this answer with some screenshots: Are nested subdomains possible with a subdomain multisite?
You might also need to set the constant COOKIE_DOMAN
to an empty value in your wp-config.php
:
define( 'COOKIE_DOMAIN', '' );
WordPress now has a support article on this. Essentially the recommended steps are as outlined by David & Michael:
- Map the domain name in DNS to your server
- Make sure this domain is registered on your server with a virtual host pointing to the WordPress directory
- Generate and install a SSL certificate on your server that includes the intended domain (technically this is optional, but restricting users to HTTP is not a good idea, and is now regularly punished by bad SEO scores)
- Update the site URL in your WordPress blog to point to the new domain
- If problems with cookies persist, define the
COOKIE_DOMAIN
inwp-config.php
.
The main difference is that instead of leaving the cookie domain empty (define( 'COOKIE_DOMAIN', '' );
), they recommend filling in the domain to which the HTTP request went:
define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST']);
This helps avoid cookie issues with multisite installations under different domain names, especially for subdirectory installations.