How to Setup WordPress Multisite with subdirectories

WordPress Multisite with Subdirectories

Last update:

This post will walk you through setting up a WordPress Multisite with subdirectories so you can manage multiple sites under different paths. e.g. site.com/support/ and site.com/eu/ etc.

Table of Contents

Setting-up WordPress Multisite with subdirectories in just five steps

Still haven’t made the decision to utilize sub-domains, subdirectories or even multisite? Take a look at this compendium of Conditionals and a list of Good and Bad Parts, to definitively help you to decide.

Hands-on Guide!

1Start from a standard WordPress site

WARNING: Do not experiment with your production site!

Work in a Staging clone, or launch a clean WordPress site. Both options take a few seconds to launch with Wetopi Specialized Managed Hosting (watch this 20sec video that shows how to Stop breaking your live WordPress).

If your hosting does not provide a Staging server,
invest 10 secs and:

Sign up to get your FREE development server now!

Once you have a standard WordPress site up and running, we are ready to enable the WordPress Multisite with subdirectories mode.

2Enable Multisite mode

To do this, you need to modify the WordPress configuration: wp-config.php
Log into your server using an ftp client and open the wp-config.php with your favorite text editor.

At wetopi, we use secure SFTP, which is the same as ftp but the connection is secure and information travels encrypted. If you are running a wetopi server, you’ll find the SFTP credentials in the Options menu → Advanced section of your Wetopi WordPress server:

We will log to enable WordPress Multisite with subdirectories using the sftp credentials
Credentials in your wetopi server “Options Menu”

Edit wp-config.php

This capture of an SFTP client shows the wp-config.php file inside the html dir:

Sftp WordPress html dir content
This SFTP client shows where you can find the wp-config.php file

Once opened with your text editor, locate the bit that says:

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

And above the line shown above, add the following lines shown below:

/** Multisite */
define('WP_ALLOW_MULTISITE', true);

Done!
Once saved, Go back to your WordPress to enable the Network.

3Network Setup

Go back to your WordPress and reload the admin page. Now you will find a new menu item, the “Network Setup” (under the Tools menu):

Once enabled WordPress Multisite with subdirectories our Tools menu shows the Network setup

Now, in the Network Setup section, you have the choice to install Multisite to work with Subdomains or Subdirectories. For the tutorial purpose, we will check the Subdirectories option. Optionally you can name the network websites. Then, click on the Install button.

4Enable the WordPress Network

After clicking the “Install” button, WordPress will generate configuration lines in wp-config.php and .htaccess

Step 1. Add the following to your wp-config …
Let’s go back to the wp-config.php, and add the prompted lines shown in step 1:

define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'yourdomain.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

This is what we ended up having in our wp-config.php:

/** Multisite */
define('WP_ALLOW_MULTISITE', true);
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'yourdomain.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
/* That's all, stop editing! Happy blogging. */

Step 2. Editing your webserver config

If you run your WordPress site with Apache web server, go back to the SFTP client and edit the .htaccess file.

NOTE: You’ll find the .htaccess in the same path you found the previous wp-config.php

Wait! At Wetopi, we are using the incredibly fast Nginx but
Nginx! it doesn’t have .htaccess!

we have a different config.

Let’s go back to our SFTP and instead of editing the .htaccess we will edit our nginx.conf

At Wetopi you’ll find the nginx.conf file in the /var/www/conf dir:

Nginx config to edit in order to Setup WordPress Multisite with sub-directories
To Setup WordPress Multisite with subdirectories, you have to edit the Nginx config.

Once opened with our editor, locate the bit that says:

location / {
    include  /var/www/conf/mime.types;

    # No php is touched for static content.
    # include the "?$args" part so non-default permalinks doesn't break when using query string
    try_files $uri $uri/ /index.php?$args;
}

And above, add (or uncomment) the following lines:

# Multisite subdirectory mode only (subdomains mode works by default)
# uncomment following if-block only if you are running a WordPress multisite under subdirectories
if (!-e $request_filename) {
  rewrite /wp-admin$ $scheme://$host$uri/ permanent;
  rewrite ^(?!^/my-db-admin)(/[^/]+)?(/wp-.*) $2 last;
  rewrite ^(?!^/my-db-admin)(/[^/]+)?(/.*.php) $2 last;
}

This is how it will look like at the end:

location = /robots.txt {
    allow all;
    try_files $uri /index.php?$args;
}

location / {
    include  /var/www/conf/mime.types;

    # No php is touched for static content.
    # include the "?$args" part so non-default permalinks doesn't break when using query string
    try_files $uri $uri/ /index.php?$args;
}


# Multisite subdirectory mode only (subdomains mode works by default)
# uncomment following if-block only if you are running a WordPress multisite under subdirectories
#
if (!-e $request_filename) {
      rewrite /wp-admin$ $scheme://$host$uri/ permanent;
      rewrite ^(?!^/my-db-admin)(/[^/]+)?(/wp-.*) $2 last;
      rewrite ^(?!^/my-db-admin)(/[^/]+)?(/.*.php) $2 last;
}

5Loading the new server config

Once, changes in the nginx.conf (or .htaccess) are saved, your server has to load the new config. If you are running a Wetopi server, this is a simple click: go to your Options menu and click the Reload button:

Reload nginx config

Go back to your WordPress Dashboard. Now you should see the new “My sites” section:

Once enabled WordPress Multisite with subdirectories our dashboard shows the My Sites section

Now, the WordPress Multisite with subdirectories feature has been fully enabled and configured.

Go to the dashboard and create your sites.

Don’t you have an account on Wetopi?

Free full performance servers for your development and test.
No credit card required.

See how Wetopi stacks up against your current hosting

Try before you buy.

With no obligation on your part, we’ll migrate a copy of your website:

No hidden small text.
No commitments.
No credit card.