36

I want to work with WordPress multisite, but I want to be able to use my own names. For example my main site is called example.com. If I want to add a new site to my multisite network it's gonna be called newsite.example.com. I want it to be newsite.com without example. Is there a way to achieve this?

I heard about domain mapping with a plugin, but I dont know if this is relevant to this question. If it is relevant I would like to know what exactly this is.

1
  • May be worth noting that to do with without a plugin you'll have to have a Dedicated IP, at least that has been my understanding.
    – Neal Jones
    Commented Feb 10, 2017 at 16:52

3 Answers 3

35

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.example' );
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.

3
  • Thanks for this, seems to work - and it did seem to need the cookie part. For me, I 1) registered a new domain, 2) pointed its nameservers toward my existing WordPress Multisite host, 3) in cPanel, did an Add-On Domain, setting the document root as the same public_html as the primary site (like you said; I didn't try it the default way, of a new directory, so not sure if that would work), and 4) changed the subsite url from oldsubdomain.primarysite.com to newdomain.com Fingers crossed, no DNS issues so far. Commented Oct 6, 2018 at 20:39
  • I love this answer...yet I have an issue. Your suggestion for changing the .htaccess, as the wordpress also gave the same modification. when I do this change, the system crashes. Any ideas of why that would be? Commented Jun 26, 2019 at 2:07
  • I like to do it this way too. Will this have risk of getting sites corrupt when Wordpress updates everytime?
    – Jornes
    Commented Mar 17, 2021 at 15:27
8

WordPress now has a support article on this. Essentially the recommended steps are as outlined by David & Michael:

  1. Map the domain name in DNS to your server
  2. Make sure this domain is registered on your server with a virtual host pointing to the WordPress directory
  3. 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)
  4. Update the site URL in your WordPress blog to point to the new domain
  5. If problems with cookies persist, define the COOKIE_DOMAIN in wp-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.

1
  • What is the difference with changing ADMIN_COOKIE_PATH, COOKIEPATH and SITECOOKIEPATH by an empty string like done by Michael? And using $_SERVER['HTTP_HOST'] instead of an empty string for COOKIE_DOMAIN? Isn't it vulnerable to HTTP Host header injection? Only changing COOKIE_DOMAIN worked for me and the only difference I noticed is that $_SERVER['HTTP_HOST'] will set the cookie domain to .subdomain.domain.tld instead of subdomain.domain.tld (which should only be useful if we have another subdomain level).
    – baptx
    Commented Apr 7, 2021 at 11:26
6

It was made possible without using a plugin a few 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.example) 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', '' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.