I recently decided to enable WordPress multisite support on this blog.  For those who are unfamiliar, multisite is a new feature in WordPress 3.x that allows for the hosting of multiple blogs in one WordPress instance.  Previously, this functionaly required separate installations.  I have always wanted to try out the new feature and the request by a colleague to host their blog seemed like an ideal opportunity.

Enabling multisite is relatively complex.  It requires manual editing of WordPress configuration files.  However, once enabled, the configuration process is relatively easy and I had no problem maintaining my existing content and graphical layout.  The installation did request that I change the blog URL from www.livens.org to livens.org, but this did not have a meaningful impact.  However, a URL issue shortly emerged.

The challenge with multisite is that it changes the path to your blog.  Prior to implementation, my blog URLs looked like the following:




Upon implementation of multisite, it changed to the following:




As you can see, multisite adds “blog” to the path.  This broke external links which would arrive at an error page.  The problem only seemed to arise in cases where the original link took the following format: https://www.livens.org/2010/09/03/roku-so-simple-and-yet-so-useful/and not https://livens.org/2010/09/03/roku-so-simple-and-yet-so-useful/.  This had to be resolved and so I explored custom Apache re-write rules to address the issue.  After quite a bit of trial and error, I came up with the following solution which I added to my .htaccess file.

Update: The first comment includes a simpler and more elegant solution to the problem.

RewriteCond %{HTTP_HOST} ^www\.livens\.org [NC]
RewriteCond %{REQUEST_URI} ^/[0-9].
RewriteRule ^(.*)$ https://livens.org/blog/$1 [L,R=301]

These rules are straightforward.  The first checks whether the incoming URL is www.livens.org. The second checks the first character after the slash and is only true if it is a number.  This was critical because it avoids the problem of redirecting either www.livens.org/blog or www.livens.org/.  It works because the old URL format always had a number after the first slash.  Finally, if both conditions are true, then it redirects to livens.org/blog/. These rules are currently in operation on the site and are working well.

I hope that this experience and coding will benefit others considering multisite.

(Visited 582 times, 1 visits today)