Multisite network admin – URL / redirect error

I followed this guide on how to set up a WordPress installation that is optimized for git deployment.

Basically, WordPress is moved into a subfolder called wordpress, index.php and wp-config.php are moved out of the subfolder, as well as wp-content.
To make that work, the path to wp-blog-header.php is adjusted, as well as the path to to wp-content.

I had this working without problems with a single site installation, but since I often have to work with multisites, I tried to create one.

Besides the warning Warning! Subdirectory networks may not be fully compatible with custom wp-content directories. everything worked as usual, with one problem:

I can’t access the network admin screens.

The site admin URL look like this: http://local.dev/wordpress/wp-admin/, but the links to the network admin look like this: http://wp1.dev/wp-admin/network/sites.php.
So you see, the /wordpress/ is missing. If I add in manually, the network admin screens load as expected.

My .htaccess looks like this:

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

and the relevant parts of my wp-config.php look like this:

define( 'WP_ALLOW_MULTISITE', true );

define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'local.dev');
define('PATH_CURRENT_SITE', "https://wordpress.stackexchange.com/");
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

I already tried to change PATH_CURRENT_SITE from /to /wordpress/.
That fixes the url, but the network admin screen won’t load because there are too many redirects, so it seems that the problem is in my .htaccess.

There I already tried this (as suggested here), but this does not solve the problem – the same error persists:

RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]

WordPress version is 4.0, the network was also started at this version.

Do you see whats wrong with this setup? How do I fix the ‘too many redirects’ error?

Edit: I investigated the issue a bit further. I tried to do the same with a single site installation and it worked without problems. My guess is that the warning message I quoted is there for a reason. Still, I would love to know if there is a fix or workaround for this. Also, I am now pretty sure that PATH_CURRENT_SITE must be /, which means it’s clearly an .htaccess issue.

2 Answers
2

network admin_url filter can rewrite network admin url.
But i don’t know it is a best way or not.

// wp-config.php
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');

// add code //
define('__WORDPRESS_CORE_DIR__', '/wordpress');

add_filter('network_admin_url', 'rewrite_my_network_admin_url', 10, 2);
function rewrite_my_network_admin_url($url, $path) {
  $networkPath = str_replace( '/wp-admin/', __WORDPRESS_CORE_DIR__ . '/wp-admin/', $url );
  return $networkPath;
}

http://chaika.hatenablog.com/entry/2018/02/03/090000 (japanese)

Leave a Comment