Latest TweetsVerify any search engine or visitor via CLI Forward-Reverse Lookup perishablepress.com/cli-forwar…
Perishable Press

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 = Designer. Developer. Producer. Writer. Editor. Etc.
Archives
24 responses
  1. Andrea_R July 7, 2010 @ 5:45 pm

    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. creative solving
    but how about individual files such as wp-config.php, cache(s), favicon.ico, logo.jpg and the others ?

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

  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.

  5. Andrea_R July 8, 2010 @ 3:45 am

    @lane just some terminology changes

  6. Jeff Starr

    @Andrew Nacin: Already mentioned in third paragraph list.

  7. Website design chennai July 12, 2010 @ 10:14 pm

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

  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 ?

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

  10. @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. Jeff Starr

    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. Vipul Patel October 13, 2010 @ 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 ]