htaccess Code for WordPress Multisite

by Jeff Starr on Wednesday, July 7, 2010 9 Responses

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.

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.

About the author

[ Jeff Starr ]

Jeff Starr is a web developer, graphic designer and content producer with over 10 years of experience and a passion for quality and detail. Jeff is co-author of the book Digging into WordPress and strives to help people be the best they can be on the Web. + Follow Jeff on Twitter and subscribe to Perishable Press for quality web-design content delivered fresh.


9 Responses

Add a comment

[ Gravatar Icon ]

hokya#1

creative solving
but how about individual files such as wp-config.php, cache(s), favicon.ico, logo.jpg and the others ?

[ Gravatar Icon ]

Andrea_R#2

Just a note that even though the subfolder blogs are indeed easier, they are still virtual. :) People expect to find them on the server and they won’t be.

[ Gravatar Icon ]

Lane#3

Has the admin-interface for WPMU changed as well with 3.0?

[ Gravatar Icon ]

Andrew Nacin#4

Something to note, those are the rewrite rules for subdirectory installs. Subdomain installs don’t need such complex rules, since they don’t need to worry about the virtual subfolders that @Andrea_R mentioned:

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

# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]

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

I really should make sure both are on a single Codex page somewhere.

[ Gravatar Icon ]

Andrea_R#5

@lane just some terminology changes

[ Gravatar Icon ]

Jeff Starr#6

@Andrew Nacin: Already mentioned in third paragraph list.

[ Gravatar Icon ]

Website design chennai#7

yes..useful coding about Multisite wordpress..Nice sharing

[ Gravatar Icon ]

asshu#8

I have installed wordpress via an auto-installer and later configured it as multisite. But when ever I create the wordpress site using auto-installer .It doesn’t give me the .htaccess file by default .So I do create an empty file with the name .htaccess in cpanel and paste the code to it.

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

# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]

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

Is it a right method ?

Trackbacks / Pingbacks
  1. Twitter Trackbacks for htaccess Code for WordPress Multisite • Perishable Press [perishablepress.com] on Topsy.com
Share your thoughts..

Read Comment Policy

Comment Rules: No spam. No profanity. Use your real name. You may use simple HTML tags for style. Wrap all code in <code> tags. Learn more.



Previous post: 2010 IP Blacklist

Attention: Do NOT follow this link!