Change WordPress Multisite: subdomains/subdirectories - Plesk

How to change WordPress Multisite Structure from subdomains to subdirectories and vice versa

If you’ve ever installed WordPress Multisite, you know the first thing it asks you to do is “Please, choose if you want the sites of your WordPress network to use subdomains or subdirectories. You will not be able to change this later.” From hereon, you’d need to follow different steps, depending on your choice, with no reversal. But life takes many turns and you may find yourself needing to change the model down the road, which WordPress doesn’t permit natively. What to do?

Here’s the verdict: you can change WordPress multisite from subdomains to subfolders and vice versa. But it requires some delicate actions, therefore we strongly suggest you backup your database, wp-config.php and .htaccess files, in case of any issues. Warning: Never do this in production.

Change WordPress Multisite from subdomains to subfolders

That is, going from http://site1.mydomain.com/ to http://mydomain.com/site1/.

Step 1

In our wp-config.php configuration file,  look for the line:

define( 'SUBDOMAIN_INSTALL', true );

and replace it with the following:

define( 'SUBDOMAIN_INSTALL', false );

Save changes.

Step 2

Go to the .htaccess file and look for the rules that are between #BEGIN WordPress and #END WordPress. You’ll have this:

# BEGIN 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]

# END WordPress

and we will replace it with:

# BEGIN WordPress

RewriteEngine On

RewriteBase /

RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin

RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]

RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^ - [L]

RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]

RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]

RewriteRule . index.php [L]

# END WordPress

Keep the changes.

Step 3

Access the database and look for the table wp_blogs, you’ll find something similar to this:

WordPress Multisite - wp_blogs table

As our intention is to move to subfolders, we must manually set all the sites of our multisite with the main domain in the domain field of the table wp_blogs. And in the path field we’ll put the name of what used to be our subdomain. This table would look like this:

WP Multisite Structure change - wp_blogs table changes
WordPress Multisite - wp_blogs table check

If you have just a few sites, you can easily do this task manually. But if you have hundreds or thousands of sites, you may want to write a small script to automate this task.

Step 4

As you know, WordPress stores all your links and so it’s necessary to have a replacement of all the URLs of all our sites. For this, you’ll need to use WP-CLI or the Search & Replace script. However, never do this manually or by making updates directly to the database, because there’s likely to be serialized information that we may lose.

Fifth step

Check that everything is working correctly.

Change WordPress Multisite from subfolders to subdomains

In case you want to pass a multisite of subfolders to subdomains, the process is exactly the same, but in reverse:

  1. For security copies of the database and the wp-config.php and .htaccess files
  2. Set the >SUBDOMAIN_INSTALL to true in wp-config.php
  3. Change the rules in the htaccess by the subdomains (more info here)
  4. Change the domain column of the wp_blogs table in all sites, establishing the subdomains of each site. Simply leave the pathfield with the bar /
  5. Through the Search & Replace or WP-CLI script, replace all URLs of the type mydomain.com/site1 with site1.mydomain.com
  6. Check that everything is working correctly.

Need a server to manage your WordPress site? Check out Plesk WordPress Edition: The right platform with all the tools you need to run a managed WordPress server – simple and secure.

Did this work for you? Let us know of any issues in the comments.

arrow icon - Plesk

How useful was this post?

Click on a heart to rate it!

Average rating 3.5 / 5. Vote count: 2

Oh no, sorry about that!

Let us know how we can do better below

Comments
  • Avatar
    markus
    Reply

    was happy to find this rather recently dated guide, but not sure this has actually been tested or really refers to recent versions of wordpress.

    using this for the first case (subdomain -> subfolder) results in multiple “subsites” sharing the identical content with the “main site” and no images displayed (default upload locations for multisite-setups have changed over the years).

Leave a Comment

Start typing and press Enter to search