Changing subdir multisite install to subdir core directory structure

The question:

Now that WordPress 3.5 is supposed to work with core files in subdirectory, I decided to move my local development setup (subdirectory multisite) to that configuration.

Fast forward and what I have is following:

wordpress (3.5 core)

wp-content (content dir, configured via WP_CONTENT_DIR and WP_CONTENT_URL)

.htaccess with:

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]

# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) C:serverwwwdevwordpress/wp-includes/ms-files.php?file=$2 [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).*) C:serverwwwdevwordpress/$2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ C:serverwwwdevwordpress/$2 [L]
RewriteRule . index.php [L]

wp-config.php with:

define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'dev.rarst.net');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

index.php with:

define('WP_USE_THEMES', true);
require('./wordpress/wp-blog-header.php');

Status:

  • network admin works at /wordpress/wp-admin/network/ but all links try to point to /wp-admin/network/ which errors Forbidden with The given path was above the root path: AH00127: Cannot map GET /wp-admin/network/ HTTP/1.1 to file
  • root site works at dev.rarst.net with admin at dev.rarst.net/wordpress/wp-admin
  • other subdir sites (dev.rarst.net/*) have broken uploads, and links to admin and stuff, hadn’t got to them yet.

The question in a nutshell – in what direction do I need to move from here to get everything working?

What admin links are even supposed to be with this setup (since core is in “real” subdir and sites are in “virtual” subdirs)?

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

Your .htaccess lines need to look like this:

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]

# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) /wordpress/wp-includes/ms-files.php?file=$2 [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]

.htaccess can’t access locations outside of the document root, that is why paths like C:serverwwwdev fail. (The code above has been tested on my localhost multisite install).

Because of the .htaccess rewrite, you don’t need to set WP_CONFIG_DIR and WP_CONFIG_URL they are calculated by WordPress accordingly. You can access your admin pages at http://dev.rarst.net/wp-admin or http://dev.rarst.net/subsite/wp-admin


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment