htaccess Code for WordPress Multisite

.htaccess made easy

For the upcoming Digging into WordPress update for WordPress 3.0, I have been working with WordPress’ multisite functionality. Prior to version 3.0, WordPress came in two flavors: “original” and “multisite” (MU). Most designers probably work with regular, one-blog installations of “regular” WordPress. The htaccess rules for all single-blog installations of WordPress haven’t changed. They are the same for WordPress 3.0 as they are for all previous versions.

But now that multisite has merged with regular-flavored WordPress, we can stick with single-blog installs (which is how things are setup by default), or we can activate multisite functionality and create an unlimited network of sites. The process is still new and there are bugs that need to be worked out, but eventually it will be a widely used WordPress feature. That said, the htaccess rules used for WordPress Multisite may change as the software continues to evolve.

Currently, multisite is easiest to setup under the following conditions:

  • WordPress for main site installed in the root directory
  • Each additional network site is created in its own subdirectory

Implementing multisite on a fresh WordPress install with these conditions seems to work great. For these types of setups, here is the HTAccess code used in WordPress 3.0:

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

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

When everything is working properly, this code is available to you on the Tools > Network options page. Of course, things don’t always go according to plan, hence the reason for posting this code. Note that these htaccess rules should be placed in your main site’s root .htaccess file. There it will do the rewrite work for your entire network of sites. No editing of the code itself is necessary – just plug-n-play.

Important Note

As Andrea_R points out, it is important to visit the Network Menu in the WP Admin to activate multisite functionality. Quote:

…simply placing the wp-config code and htacess code does not actually *enable* the network? You MUST go to the Network menu and click the button to set up the tables.

Bonus: wp-config.php code

In addition to the above htaccess code, WordPress multisite requires the following code in your main site’s wp-config.php file:

define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false );
$base = '/';
define( 'DOMAIN_CURRENT_SITE', 'example.com' );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );

This code should be placed just above the line that says “That’s all, stop editing! Happy blogging.”. Unlike the htaccess code, this code requires editing: replace the “example.com” with your main site’s domain. Note that this code is also available in under Tools > Network when everything is working properly.

And a quick reminder..

In addition to the previous two chunks of code, you also need to create a directory named “blogs.dir” in your main site’s wp-content directory. This directory is for media uploads for your entire network of sites. Note that the blogs.dir directory must be writable by the web server with the same permissions settings as the wp-content folder.