wetopi-knowledge-base.png

How to Setup WordPress Multisite with subdirectories

This post will help us to setup a WordPress Multisite with subdirectories so we can manage multiple sites under different paths. e.g. mysite.com/support/ mysite.com/eu/

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!

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. Backup, or even better work with a clone, or simply start a clean WordPress. Both options just take a few seconds with Wetopi (watch this 20sec video Stop breaking your live WordPress).

If your hosting does not provide staging,
invest 10 secs!
Sign up and get your free development server

Once we 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, we need to modify our WordPress configuration: wp-config.php
Let’s log into our server, here at Wetopi, we’ll use a simple and secure SFTP and open the wp-config.php with our favorite text editor.

We’ll find the sFTP credentials in the Options menu → Advanced section of our Wetopi clone:
We will log to enable WordPress Multisite with subdirectories using the sftp credentials

This capture shows our wp-config.php file inside the html dir:
Sftp WordPress html dir content

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

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

And above, we will add the following lines:

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

Done!. Once saved, we can go back to our WordPress admin panel.

3 Network Setup

If we refresh our admin page, we should now find Network Setup under the Tools menu:
Once enabled WordPress Multisite with subdirectories our Tools menu shows the Network setup

In this new Network Setup section, we decide if we want to install Multisite to work with Subdomains or Subdirectories. In our case, we check the Subdirectories option. Optionally we can name our network websites as well. Then, click on the Install button.

4 Enabling the Network.

Once clicked the “Install” button, WordPress will generate some configuration lines to add in wp-config.php and .htaccess.

Wait! Wetopi server runs Nginx! we don’t 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 our 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, we will 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 what we’ll ended up having:

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 our nginx.cong are saved we have to reload our new nginx config: Log into your machine or in our case Wetopi, a containerized server, we will do a simple “Stop” + “Start” of our clone.

Once we go back to our WordPress Dashboard we should see our 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.

We just need to go to the dashboard and create our 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 (No Ratings Yet)
Loading...
How to Setup WordPress Multisite with subdirectories
Share this post