How to enable multi sites using sub directories in WordPress 3

How to enable multi sites using sub directories in WordPress 3

December 14th, 2010

Using Multi sites in WordPress 3One of the coolest features of WordPress 3.x is the ability to add multiple sites to any domain. This means that you can control multiple sites on your domain all from one place – very cool. I spent a lot of time banging my head against the keyboard trying to get this to work, so discovering multi sites was a real blessing.

Recently I needed to add a blog section to http://stereotyperecords.co.za so that individual users could update and post their thoughts in addition to the content that appears on the main site. One of the challenges is that the new sites need to use sub-directories and not sub-domains, which is what WordPress forces it to do at first.

Here’s how it goes down.

First, backups. Make copies of your wp-config.php file as well as your .htaccess file. You’ll need FTP access to get to your .htaccess file.

Next, you’ll need to disable all of your active plugins in order to complete the installation. Not all plugins are multi-site compatible, so take care here. From what  I can see Google XML site maps and Flickr Photo Albums are not compatible, so if you rely heavily on these – think about it…

Now add the following line to your wp-config.php file:

define('WP_ALLOW_MULTISITE', true);

Once you’ve added this line, in your WordPress dashboard you have to visit Tools -> Network and set up the network. (source)

Follow the instructions provided and you’ll be on your way to getting multi sites enabled.

During the activation of Multi Site a few lines of code need to be added to wp-confg.php. One of those lines states:

define( 'SUBDOMAIN_INSTALL', true );

That line tells WordPress to use subdomain addon sites.

Change it to

define( 'SUBDOMAIN_INSTALL', false );

and you will now be able to create subdirectory sites.

The problem now is that WordPress will force an addition to your slug in the form of siteurl/blog/newsite

To get around this, you need to remove the /blog/ with a slight change to the .htaccess rules you added earlier. Replace the code WordPress give you:

# BEGIN WordPress
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]

# END WordPress

With this code:

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]

(source)

You will now be able to create multi sites without the /blog/ inserted into your slug.

If you nee some more visual assistance, check out this video tutorial on how to implement WordPress multi sites:

  • Lester

    Okay, so it looks like WP Super Cache is also not compatiable with multi site mode – this might be a deal breaker for a lot of folks…

    You’ll also need to edit the permalink structure in your newly added sites – check that the multi site installation has not added the /blog/ slug to your permalinks

  • http://www.wanteds.co.za Jacques

    Hi

    Thanks for the tutorial.

    Do you perhaps know whether it is compatible with Classipress?

    Rgds
    J

    • Lester

      Hi Jacques,

      I’m glad that you found the information useful. I have no experience working with Clasipress ( I like the theme though)so I canbut say how well it will work.

      I’ve checked the latest release notes and it says that the theme is multi site compatible, so I think you should be fine. My advice is to set up a local installation and then trial it.

      Good luck!