wetopi-knowledge-base.png

How to Setup WordPress Multisite with subdirectories

This post will guide you on how to setup a WordPress Multisite with subdirectories so you can manage multiple sites under different paths. e.g. mysite.com/support/ mysite.com/eu/ etc.

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!

Setting-up WordPress Multisite with subdirectories in just five steps.

1 Starting from a standard WordPress site.

WARNING: Do not experiment with your production site! period and backups. Work with a clone, or launch a clean WordPress site. Both options takes a few seconds to launch with Wetopi Specialized Managed Hosting (watch this 20sec video Stop breaking your live WordPress).

If your hosting does not provide staging server,
invest 10 secs and!
Sign up and 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.

2 Enabling Multisite mode.

To do this, you need to modify the WordPress configuration: wp-config.php
Log into your server, Use a simple and secure SFTP and open the wp-config.php with our favorite text editor.

You’ll find the sFTP credentials in the Options menu → Advanced section of the Wetopi clone:

We will log to enable WordPress Multisite with subdirectories using the sftp credentials

This capture shows the wp-config.php file inside the html dir:

Sftp WordPress html dir content

Once opened with the 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 admin panel.

3 Network Setup

Refresh the admin page, you should now find Network Setup under the Tools menu:

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

In 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.

4 Enabling the Network.

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

Wait! Wetopi server runs on Nginx! it does not have .htaccess!
Don’t worry, Wetopi Nginx server comes with a nginx.conf with its WordPress Multisite with sub-directories configuration ready to be enabled.

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. Add the following to your .htaccess …

The config shown is for apache web servers. We at Wetopi are using the incredibly fast Nginx tuned exclusively for WordPress. Let’s go back to our SFTP and edit our nginx.conf, placed inside “conf” dir:

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

Once opened with our editor we have to locate the bit that says:

server {
  # Running port
  listen 80;
  server_name 127.0.0.1;
  root /var/www/html;
  index index.php;

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:

server {
  # Running port
  listen 80;
  server_name 127.0.0.1;
  root /var/www/html;
  index index.php;

  # Multisite subdirectory mode only (subdomains mode works by default)
  # uncomment following if-block only if you are running a WordPress multisite with 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;
  }

5 Loading our new server config.

Once, changes in the nginx.cong are saved, reload the new nginx config: Log into your machine or in our case Wetopi, a containerized server, we will do a simple “Stop” + “Start” of the clone.

Go back to your WordPress Dashboard and you should see 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.

At wetopi, we want to minimize the friction that every professional face when working and hosting WordPress projects.

In short, we are just techies passionate about WordPress. With wetopi, a specialized WordPress hosting, we want to go further to offer professionals and agencies a platform to work efficiently and effectively.

Not a wetopi user?

Try now – you'll find an efficient way to work with WordPress

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


1 Star2 Stars3 Stars4 Stars5 Stars (19 votes, average: 4.63 out of 5)
Loading...
How to Setup WordPress Multisite with subdirectories