Spring Sale! Save 30% on all books w/ code: PLANET24
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.

About the Author
Jeff Starr = Designer. Developer. Producer. Writer. Editor. Etc.
Digging Into WordPress: Take your WordPress skills to the next level.

24 responses to “htaccess Code for WordPress Multisite”

  1. I’ve tried to implement the above but it seems I’m not doing something correctly.

    Am I suppose to put those .htaccess rules in the root WP .htaccess or in the subdomain .htaccess?

    Some of the plugins that I need don’t work with the multisite, so I think I’m better installing it as a separate installation….please help as to which .htaccess am i suppose to put…Thanks in advance

  2. I have multisite working fine with one sub site. The main site, www.mydomain.com redirects to mydomain.com (no www). When I go to the sub site, www.mydomain2.com, it redirects to mydomain.com/wp-signup.php?new=mydomain2.com. But www.mydomain2.com works fine.

    Basically, I want both to always go to www. And if the visitor does not enter the www, it should go to the www for subsites and not redirect to the main domain.

  3. Can you maybe add that 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.

    I’m seeing some people show up in the support forums who had changed their htaccess & config files, and never visited the network menu. ;)

  4. Jeff Starr 2011/02/19 4:33 pm

    @Andrea_R: Done! :)

  5. when moving MU from localhost to a temp server, there’s some rewrite conditions in the htaccess, do they need to be modified too?

    One of the Rewrite cond starts likr this: C:/wamp/www/

    I’m really struggling to move my MU from localhost to a test server :-(

  6. Trung Hieu 2011/05/18 6:46 pm

    Hi

    I’m using WP MU on host Godaddy.

    I was upload .htaccess file, and always got error 500 Internal.So I delete and don’t use it !

    Do you know why ?

  7. Jon Huther 2011/05/19 3:41 am

    “Do you know why ?”
    What’s in it?

  8. mrtvy.kenny 2012/01/21 4:17 am

    thanks a lot, my wordpress generated htaccess script that was NOT working, you saved me after 2 hours of trying to solve this. im so angry right now.. :(

  9. Hi. Andrea, thanks for the added advice. I don’t know which button you mean to set up the tables… Help please?

  10. Goin berserkie!

    Testing MS and even when followed to a tee step by step, http://sgcdevlabs.dlinkddns.com/markbolden/test gets: “The requested URL /markbolden/test was not found on this server.”

    Server: Ubuntu 12, Apache 2.x, everything else works!! Just not MS.

    Any ideas? rewrite is on, and I have tried two different servers and multiple CLEAN re-installs with the same result.

    -??

    • Hi Sparks, there’s a lot of moving parts involved with MultiSite that all need to be addressed/configured before it will work. For example the wp-config.php rules need to be in place, WP settings, etc. Not sure if this is useful info for you or not, but the MultiSite code does work once everything else is in place (for anyone else who may be reading).

  11. Hi! I was in trouble since I had accidentally deleted my .htaccess in my WP Network installation. I’ve tried with your code but it wasn’t working. I’ve finally come back online using this:

    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]

    Cheers!

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 »
Banhammer: Protect your WordPress site against threats.
Thoughts
I live right next door to the absolute loudest car in town. And the owner loves to drive it.
8G Firewall now out of beta testing, ready for use on production sites.
It's all about that ad revenue baby.
Note to self: encrypting 500 GB of data on my iMac takes around 8 hours.
Getting back into things after a bit of a break. Currently 7° F outside. Chillz.
2024 is going to make 2020 look like a vacation. Prepare accordingly.
First snow of the year :)
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.