bchwordpress-multisite

Configure WordPress Multisite to use subdirectories instead of subdomains

NOTE: We are in the process of modifying the file structure and configuration for many Bitnami stacks. On account of these changes, the file paths stated in this guide may change depending on whether your Bitnami stack uses native Linux system packages (Approach A), or if it is a self-contained installation (Approach B). To identify your Bitnami installation type and what approach to follow, run the command below:

 $ test ! -f "/opt/bitnami/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."

The output of the command indicates which approach (A or B) is used by the installation, and will allow you to identify the paths, configuration and commands to use in this guide. Refer to the FAQ for more information on these changes.


NOTE: These steps should be performed before creating a new site.

Approach A: Bitnami installations using system packages

Follow the steps below depending on your installation type:

  • Edit the /opt/bitnami/wordpress/wp-config.php and modify the definition as shown below:

      define('SUBDOMAIN_INSTALL', false);
    
  • Edit the /opt/bitnami/apache2/conf/vhosts/wordpress-vhost.conf file and replace the following block:

      # BEGIN WordPress Multisite
      # Using subdomain network type: https://wordpress.org/support/article/htaccess/#multisite
      RewriteEngine On
      RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
      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 Multisite
    

    With this:

      # BEGIN WordPress Multisite
      # Using subfolder network type: https://wordpress.org/support/article/htaccess/#multisite
      RewriteEngine On
      RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
      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 Multisite
    
  • Edit the /opt/bitnami/apache2/conf/vhosts/wordpress-https-vhost.conf file and perform the same replacements as before.

  • Restart Apache to apply the changes:

      $ sudo /opt/bitnami/ctlscript.sh restart apache
    

Approach B: Self-contained Bitnami installations

Follow the steps below depending on your installation type:

  • Edit the /opt/bitnami/apps/wordpress/htdocs/wp-config.php and modify the definition as shown below:

      define('SUBDOMAIN_INSTALL', false);
    
  • Edit the /opt/bitnami/apps/wordpress/conf/httpd-app.conf file and replace the existing URL rewriting rules so that they look like this:

      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]
    
  • Restart Apache to apply the changes:

      $ sudo /opt/bitnami/ctlscript.sh restart apache
    
Last modification June 16, 2021