0

Here's the situation:

Configuration

I have a WordPress multisite setup where different sites are on different domains. Some of those sites are contained in a subfolder in their domain, some are not. For the sites where they are in a subfolder, the subfolder name is the same across all sites.

Here's the examples:

  Site    |    URL
-----------------------
Main site | example.com
Site A    | sitea.com
Site B    | siteb.com/foo
Site C    | sitec.com/foo
Site D    | sited.com

Here is the relevant part of my wp-config.php:

/* Multisite */
define( 'WP_ALLOW_MULTISITE', true );
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'example.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

Here is my .htaccess:

# BEGIN WordPress
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]
# END WordPress

Problem

In this configuration, Main Site and Sites A & D work, but Sites B & C give a 500 error. If I change RewriteBase / to RewriteBase /foo/ then the reverse is true: Sites B & C work, but Main Site, Site A & site D give a 500 error.

If the effects of RewriteBase /foo/ were applied on a conditional basis only to domains where the URI started with /foo, then I think that would solve the problem. Unfortunately, I do not understand how WordPress and .htaccess interact well enough to do this.

Does anyone have any suggestions?

Thank you.

1 Answer 1

0

Found a solution for anyone who may stumble upon this. Basically, each part of a standard WordPress htaccess now has two RewriteConds: one for when it is in a subfolder, and another for when its not. Depending on that evaluation, the appropriate RewriteRule is applied.

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteCond %{REQUEST_URI} ^/([_0-9a-zA-Z-]+/)wp-admin$
RewriteRule ^([_0-9a-zA-Z-]+/)wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_URI} !^/([_0-9a-zA-Z-]+/)wp-admin$
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]


RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]


RewriteCond %{REQUEST_URI} ^/([_0-9a-zA-Z-]+/)(wp-(content|admin|includes).*)
RewriteRule ^([_0-9a-zA-Z-]+/)(wp-(content|admin|includes).*) $2 [L]

RewriteCond %{REQUEST_URI} !^/([_0-9a-zA-Z-]+/)(wp-(content|admin|includes).*)
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]


RewriteCond %{REQUEST_URI} ^/([_0-9a-zA-Z-]+/)?(.*\.php)
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]

RewriteCond %{REQUEST_URI} !^/([_0-9a-zA-Z-]+/)?(.*\.php)
RewriteRule ^(.*\.php)$ $1 [L]


RewriteCond %{REQUEST_URI} ^/foo/
RewriteRule . foo/index.php [L]

RewriteCond %{REQUEST_URI} !^/foo/
RewriteRule . index.php [L]


# END WordPress

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.