Select Page

Working with Multisite in WordPress has many advantages. You can easily manage and create similar websites, while they still act as separate sites for visitors. While you can easily change subdomain directories from one to another, replacing the main domain with a subdirectories content and vice versa is a different topic. It happened to me lately, when building the relaunch of a website with a multisite and there are probably many more reasons for this case to happen.

If you are switching subdirectory urls, you can just do so in the „Sites“ Menu as a Super Admin. But that is not possible for the primary site. Instead, you will have to change the settings in the database and the wp-config file.

First thing you should do, is to take a backup of your database. Don’t start without having one!

Changing the database values

When changing the primary domain of your site, there are a few values to change in the database: (wp_ is the database prefix. If you are using something else (xxx), look for xxx_…)

And ALWAYS be careful about the exact URLs you are changing. WordPress has different rules for different fields. The wp_site and wp_blogs tables can NOT have http:// or a trailing slash at the end of the domain name, whereas in the wp_options table, it is required to have the http:// at the beginning. In the wp_sitemeta table it is required to have http:// at the beginning and a trailing slash at the end.

Make sure, whenever you implement a new URL, to use the same format as the one it says when opening the database field.

The current primary domain:

You will need the tables wp_options, wp_site, wp_sitemeta and wp_blogs

Database Table Values to change
  • change primary siteurl to its new url
  • change primary home url to its new url (this might be on page 2)
  • change primary domain url to its new url
  • change primary siteurl to its new url
  • change the paths of the primary domain to its new path

You can now navigate to the new subdomain, with the contents of the former primary domain.

But be careful, don’t try to load the primary URL right now, as it has no content.

The current multisite domain:

The first thing you need to know about the subdomain, that is supposed to become the primary domain, is its ID. You can find it, by navigating to Network Admin —> Sites and hover over the right sites name. In the link you should see at your lower left corner in the end, it will say ID=# (# being the number of the ID). In my case, it is the number 12.

Each subsite also has a set of database tables, that corresponds to this id. You will need to find it in wp_blogs and its wp_#_options table.

Database Table Values to change
  • change the paths of the new domain to the primary path
  • change subdomains siteurl to the primary url
  • change subdomains home url to the primary url (this might be on page 2)

Adapt the wp_config file

Make sure, to comment out any predefined URLs in the wp-config.php file. These could be:

define( 'WP_HOME', '' );

define( 'WP_SITEURL', '' );

After that, you have to manually tell your server, which is the main Blog-ID to use for the primary domain in your multisite settings.

define('MULTISITE', true);

define('SUBDOMAIN_INSTALL', false);

define('DOMAIN_CURRENT_SITE', '');

define('PATH_CURRENT_SITE', '/');

define('SITE_ID_CURRENT_SITE', 1);

define('BLOG_ID_CURRENT_SITE', 12);

In the line BLOG_ID_CURRENT_SITE change the number to the Blog-ID of your new primary domain. For me, that would be again the number 12.

Now, you can go back to your site, and when loading the primary url, you should find your former subdomain here.

Changing the Primary Site in your Multisite Settings

When logged in to your new primary domain, you can navigate to Dashboard —> My Sites.

In the first line, you can define the Primary Site of your Multisite. Change it to the current primary site.


Change Primary Site

Replace links in your new domains

To make sure, all URLs in every setting were changed, I recommend using the Velvet Blues Update URLs Plugin and to do a Search and Replace. It is compatible with Multisite and you can go subsite by subsite. After activation, navigate to Tools —> Update URLs on the new subsite and replace all links with the old url to the new one. Also navigate to Update URLs in on the new primary domain and replace all links with the old path the primary domain one.

Search and Replace Links

Search and Replace Links