Search code examples
wordpress.htaccessurl-rewritingpermalinksmultisite

Wordpress 4.9.4 multisite (subdirectory) permalinks broken after domain mapping


We have a Wordpress 4.9.4 multisite with subdirectory type site structure. Installed not directly in www, but in a subdirectory.

The base url is like: http://a.a/a
A site url is like: http://a.a/a/a
A page url is like: http://a.a/a/a/a
Permalinks are working normally in any setting.

We started to map domains to subsites using the built-in Wordpress functionality (no plugins) by setting the new domain name in Sites->Site->Edit
eg.: http://a.a/a/a -> http://b.b

Both relevant values are set (home and base url) in the wp_options table and the sites are running.

PROBLEM: We can only use the default permalink structure, as any other throws a 500 Internal Server Error.
eg.: http://b.b/?page_id=10 works, http://b.b/b doesn't.

wp-config.php contains the following (may not be relevant):

// Multisite
define( 'WP_ALLOW_MULTISITE', true );
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'a.a');
define('PATH_CURRENT_SITE', '/a/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
// Domain mapping cookie settings
define('ADMIN_COOKIE_PATH', '/');
define('COOKIE_DOMAIN', '');
define('COOKIEPATH', '');
define('SITECOOKIEPATH', '');

.htaccess:

RewriteEngine On
RewriteBase /a/
RewriteRule ^index\.php$ - [L]
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]

QUESTION: How can we make http://b.b/b type permalinks work?

EDIT: After a lengthy search and some trial-and-error, I've found a half-solution.

In the permalinks settings choose Custom Structure, and enter index.php/%postname%

This way though we have to use http://b.b/index.php/b link structure, but at least it's not ?page_id=123. Wordpress already has rules to eliminate index.php from the url, but it doesn't seem to extend to mapped domains.

Do you know a way to eliminate index.php from the url in mapped domains?


Solution

  • THE MODIFIED HTACCESS THAT WORKS:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    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).*) a/$2 [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ a/$2 [L]
    RewriteRule . index.php [L]
    

    In addition, make sure that the .htaccess owner user has correct access and usage privileges of the mod_rewrite module.