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 );
# 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:
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:
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:
- For security copies of the database and the wp-config.php and .htaccess files
- Set the >SUBDOMAIN_INSTALL to true in wp-config.php
- Change the rules in the htaccess by the subdomains (more info here)
- 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 /
- Through the Search & Replace or WP-CLI script, replace all URLs of the type mydomain.com/site1 with site1.mydomain.com
- 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.
8 Comments
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).
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?
Hey Erdal, best contact our support with this: https://support.plesk.com/hc/en-us
Thanks Debbie.
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.
Hi Danielle,
We kindly suggest you submit a request with our support team, as they can have a look at your specific case. Hope this can help.
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?
Hi Aleks, we suggest you submit a request with our dedicated support, as they can look into your specific setup. Hope this helps.