Save 25% on Wizard’s SQL for WP w/ code: WIZARDSQL
Web Dev + WordPress + Security

htaccess Code for WordPress Multisite

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.

Jeff Starr
About the Author
Jeff Starr = Creative thinker. Passionate about free and open Web.
Digging Into WordPress: Take your WordPress skills to the next level.

24 responses to “htaccess Code for WordPress Multisite”

  1. Avatar photo

    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.

  2. Avatar photo

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

  3. Avatar photo

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

  4. Avatar photo

    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.

  5. Avatar photo

    @lane just some terminology changes

  6. Avatar photo
    Jeff Starr 2010/07/08 4:56 am

    @Andrew Nacin: Already mentioned in third paragraph list.

  7. Website design chennai 2010/07/12 10:14 pm

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

  8. Avatar photo

    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 ?

  9. Dashboard is not working in 3.01 WP. Any ideas
    b…

  10. Avatar photo

    @Jeff and @Bruce

    Hi, bruce! I got the same problem. “503 Service not Available” for dashboard. While my front end is working fine.

    I am searching on internet for solution since 4-5 hours and understood that it’s happening because of wild card sub domain.

    To solve the problem you need to do something with .htaccess file.

    I let you know, If I find the solution.

  11. Avatar photo

    I just completed a project where dashboards were not working for sub-domain sites. While investigating, I found that WordPress had provided the subdirectory htaccess on the Tools > Network page. I have also seen subdirectory MultiSite provide the htaccess for sub-domains, so definitely make sure you’re using the correct htaccess.

  12. Avatar photo
    Vipul Patel 2010/10/13 12:59 pm

    hi, Jeff!

    wow, I didn’t know that.. thanks for sharing the secret.. ha ha.. :D

    Appreciate a lot..

Comments are closed for this post. Something to add? Let me know.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
Blackhole Pro: Trap bad bots in a virtual black hole.
Thoughts
Plugin updates! All of our free and pro plugins ready for WordPress 6.2.
Daylight savings is a complete waste of time and needs to be eliminated.
Got a couple of snow days here in mid-March. Fortunately it's not sticking.
I handle all email in real time as it comes in, perpetually clear inbox for years now.
Added some nice features to Wutsearch search engine launchpad. Now 21 engines!
.wp TLD plz :)
Nice collection of free SEO APIs and user-agent lookups for Googlebot, Bingbot, Applebot, YandexBot, and more.
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.