Home > Help Center > Applications > WordPress > WordPress Multisite Switching Network Types

WordPress Multisite Switching Network Types

In a series of articles, we looked at various options of installing and importing WordPress MultiSite.

In this article we will show how to switch between domain-based (sub-domain) and path-based (sub-directory) installations of Multisite.

To run a new installation of a WordPress Multisite, you must apply the following changes in two files - wp-config.php and .htaccess.

Domain-Based (sub-domain) Multisite

wp-config.php

` / Multisite /

define( 'WPALLOWMULTISITE', true ); define('MULTISITE', true); define('SUBDOMAININSTALL', true); define('DOMAINCURRENTSITE', 'wpmusubfolder.example.com'); define('PATHCURRENTSITE', '/'); define('SITEIDCURRENTSITE', 1); define('BLOGIDCURRENT_SITE', 1);

/ That's all, stop editing! Happy blogging. / `

.htaccess

`

WPMU SUB-DOMAIN

RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L]

add a trailing slash to /wp-admin

RewriteRule ^wp-admin$ wp-admin/ [R=301,L] RewriteCond %{REQUESTFILENAME} -f [OR] RewriteCond %{REQUESTFILENAME} -d RewriteRule ^ - [L] RewriteRule ^(wp-(content|admin|includes).) $1 [L] RewriteRule ^(..php)$ $1 [L] RewriteRule . index.php [L]

END WPMU

`

Path-Based (sub-directory) Multisite

wp-config.php

` / Multisite /

define( 'WPALLOWMULTISITE', true ); define('MULTISITE', true); define('SUBDOMAININSTALL', false); define('DOMAINCURRENTSITE', 'wpmusubfolder.example.com'); define('PATHCURRENTSITE', '/'); define('SITEIDCURRENTSITE', 1); define('BLOGIDCURRENT_SITE', 1);

/ That's all, stop editing! Happy blogging. / `

.htaccess

`

WPMU SUB-DIRECTORY

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 %{REQUESTFILENAME} -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 WPMU

`

As you may have noticed the difference between the two code blocks in wp-config.php file consists of one single word:

For a domain-based network (sub-domain):

define( 'SUBDOMAIN_INSTALL', true );

For a path-based network (sub-directory):

define( 'SUBDOMAIN_INSTALL', false );

Convert sub-directory multisite into sub-domain multisite

Our Test Multisite Network consists of four sub-directory sites:

multisite switch network types

Now we create wildcard DNS record to point all subdomain requests to multisite directory:

multisite switch network types

Click My Sites > Network Admin > Sites

multisite switch network types

Hover the mouse over URL and click Edit link:

multisite switch network types

You are not allowed to edit the default multisite domain so we go back and continue with the second URL.

multisite switch network types multisite switch network types

You must replace the sub-directory with sub-domain URL – you can use any keyword instead of sub-directory slug (site2):

multisite switch network types

Following the same steps edit all URLs:

multisite switch network types

Time to test our sub-domain multisite network – all sites work fine.

multisite switch network types

Convert sub-domain multisite into sub-directory multisite

Before we begin editing the code, we need to make sure that in our sub-directory installation there is no conflict between pages (e.g. example.com/pagename) and sites (e.g. example.com/sitename).

Actually we'll try to provoke URL conflict by editing the Hello World post and its slug.

Click My Sites > Site Two > Dashboard:

multisite switch network types

Click Settings > Permalinks:

multisite switch network types

Change permalinks type to Post name and click Save Changes button:

multisite switch network types

Now we are going to edit the Hello world! post (you can create new post):

multisite switch network types

The most important thing is to edit the post slug to sub-directory like it is shown below:

multisite switch network types

Now we'll try to build a sub-directory multisite using the above post slug (sub-directory) as a sub-directory slug:

http://wpmusubfolder.example.com/sub-directory/

Note: Don't forget we intentionally try to provoke URL conflict.

First edit the row in wp-config.php file:

define( 'SUBDOMAIN_INSTALL', false );

Then replace the sub-domain block of code in .htaccess file with the sub-directory block:

`

WPMU SUB-DIRECTORY

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 %{REQUESTFILENAME} -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 WPMU

`

Open My Sites > Network Admin > Sites and edit all sub-domain URLs with sub-directory ones:

multisite switch network types

Here is our URL spy:

multisite switch network types

Click Sites > All Sites to make sure all URLs are edited correctly:

multisite switch network types

Since we received no error report we can visit successfully Site Two:

http://wpmusubfolder.example.com/sub-directory/

multisite switch network types

May be we'll get an error when clicking on the post title?

No luck – the post is loading correctly:

multisite switch network types

But ... do you notice the URL:

http://wpmusubfolder.example.com/sub-directory/sub-directory/

There is one more slug instance (/sub-directory/) added by WordPress itself.

Let's check if that change concerns only the particular case or there is per network basis global change.

Click Site Two > Dashboard

Click Settings > Permalinks:

multisite switch network types

No, it's not a matter of luck - WordPress automatically adds the sub-directory slug in front of the post slug.

Let's check Site Four Settings – again its slug sub-directory4 is included before any path type:

multisite switch network types

Let's make one final attempt to cause WordPress error by trying to create new multisite with double slug

sub-directory/sub-directory/

thus duplicating the existing post URL:

http://wpmusubfolder.example.com/sub-directory/sub-directory/

Click My Sites > Network Admin > Sites

Click Add New button:

multisite switch network types

The info under the input field says we are not allowed to enter forward slash (/) but we do insist and finally we get our error:

multisite switch network types

WordPress allows easy and problem free switching between sub-directory multisite and subdomain multisite.

One final note: you cannot switch from Sub-directory to Sub-domain when running on 127.0.0.1 or localhost. This can potentially cause an endless loop of reauth=1 on your root site due to cookie handling.

#wordpress #multisite

Still not finding what you're looking for?

Contact our support team with any additional questions or concerns.

Contact support