Plesk & SocialBee have teamed up. Save 30% now!

Changing WP 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 WP 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

8 Comments

  1. 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).

  2. Hi, I did all the steps in the article to change from subdomains to subdirectories, but when I go to the subdirectory site’s main page it shows the contents of the subdirectory in the file system instead of the site. I checked wp-config.php and .htaccess and they are correct. I updated the sites in the wp-blog table. I think link replacement was correct, too. Do you have any ideas about why it doesn’t work?

  3. Hi, I’m doing this in reverse (subdirectories to subdomain) but when I attempt to create a new site, it says “Safari cannot open the page because the server cannot be found.

  4. I have switched from subdomain to subdirectory, on local xampp installation it works, but on the live version, css is broken on subdirectories. Do you have any idea what I can try?

Add a Comment

Your email address will not be published. Required fields are marked *

GET LATEST NEWS AND TIPS

  • Yes, please, I agree to receiving my personal Plesk Newsletter! WebPros International GmbH and other WebPros group companies may store and process the data I provide for the purpose of delivering the newsletter according to the WebPros Privacy Policy. In order to tailor its offerings to me, Plesk may further use additional information like usage and behavior data (Profiling). I can unsubscribe from the newsletter at any time by sending an email to [email protected] or use the unsubscribe link in any of the newsletters.

  • Hidden
  • Hidden
  • Hidden
  • Hidden
  • Hidden
  • Hidden

Related Posts

Knowledge Base