How to fix broken external links with WordPress multisite

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:

https://livens.org/2010/09/03/roku-so-simple-and-yet-so-useful/

or

https://www.livens.org/2010/09/03/roku-so-simple-and-yet-so-useful/

Upon implementation of multisite, it changed to the following:

https://livens.org/blog/2010/09/03/roku-so-simple-and-yet-so-useful/

or

https://www.livens.org/blog/2010/09/03/roku-so-simple-and-yet-so-useful/

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 755 times, 1 visits today)

7 thoughts on “How to fix broken external links with WordPress multisite”

  1. This is a well-known issue. 🙂 It only happens in a sulbfolder setup on the main site in the network.

    No need for rewrite rules to add more overhead, just go to Super Admin -> Sites, edit the main blog and remove the /blog.

    1. Andrea,

      Thank you for your comment! I somehow missed the simple solution you suggest and have now implemented the change. It works perfectly.

    2. Hi – So glad you have this info here. It’s too bad it’s not included in the official codex (or if it is I missed it!) about the removing the /blog in the permalinks. These little details are everything. cheers

    3. @ Andrea, genius with WP you are. Reading your saved my backside just a few moments ago. My Multisite installation is a sub-domain install and today I made my first post after setting up the network. The links were broken for sure. I check the permalink structure and sure enough Multisite added the /blog.

      Thank goddness for this post and the comments.

      1. Steve,

        Thank you for your comment! I am glad that it helped you. It caused me great frustration too and thanks to Andrea there was a far simpler solution than the one I had coded.

Leave a Reply to Andrea_R Cancel reply

Your email address will not be published. Required fields are marked *

* Copy This Password *

* Type Or Paste Password Here *

This site uses Akismet to reduce spam. Learn how your comment data is processed.