Switching to WordPress MultiSite Breaks Links

As of WordPress 3.1 you can NO LONGER remove the blog slug via the method described in this post! – Feb 28 2011

Warning: WordPress MultiSite is not for the newbie!

Most people I know who are using MultiSite (formerly WPMU) are people who have always been using that fork of WordPress. With the advent of MultiSite, a built in way for people to move from single ‘blog’ installs of WordPress to a multiple site structure, more and more users want to move to it, which is great. But. There are some weird ‘problems’ with MultiSite that cause a lot of users to think it’s broken. It’s not, it’s just different.

My friend Andrea wrote a nice tutorial about how to create a network, and generally when I need help, I scan WPMU Tutorials first. Or I tweet at her. One of the things we’ve talked about is the way WordPress MultiSite changes your blog links.

When I changed http://ipstenu.org from single to multi, my links were changed from http://ipstenu.org/YYYY/MM/PostName to http://ipstenu.org/blog/YYYY/MM/PostName, which I did not want! Thankfully, I knew a lot of people had this problem beforehand and I fixed it quickly, which I will explain here, but first, here’s why it’s done that way.

Normally, when we use pretty permalinks (that’s the part of your URL that looks ‘pretty’ instead of code-like) on a blog, all we have to worry about is not conflicting with post names and page names. If you have an about page, generally the URL is http://ipstenu.org/about. Since WordPress has to translate http://ipstenu.org/?p=2 into that to be pretty, you can’t also have a blog post with the same URL. How would the software know WHICH page you wanted? Simple enough. For details on that, you can read Otto’s post on Category in Permalinks Considered Harmful.

When you add in MultiSite, suddenly the code has to check for something more: is this new Site named something that breaks my existing links?

There are two kinds of MultiSite, and I use them both. You have SubFolders and SubDomains. Subfolders gets you URLs like http://ipstenu.org/code and SubDomains gets you http://halfelf.org/. If you use SubFolders, WordPress takes an extra step to make sure that pages named ‘code’ don’t break when you have a new blog with the same name. To help do that, it kicks your blog URLs from your main blog (i.e. http://ipstenu.org/) up a level to a new URL: http://ipstenu.org/blog/. For those of us who move from Single to Multi, this breaks our old links.

Thankfully there are a couple fixes which can tide you over until WordPress 3.1 is released. The developers plan on having this ‘fixed’ or at least editable by then, so at the worst, you can go from having a blog slug to ‘news’ or ‘pasta’ or whatever.

.htaccess

If you want to keep the blog folder, but you want to redirect your old posts, .htaccess is your friend.

If I wanted to redirect all YYYY/MM/DD posts to /blog/… I would add this:

 
RewriteRule ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ http://ipstenu.org/blog/$1/$2/$3/$4 [L,R=301]

What I actually did on another site was this:

RewriteRule ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ http://domain.com/blog/$4 [L,R=301]

And I changed my permalinks to just post name. This was risky, in a way, but it matches how I use the site better.

Plugins

There are a couple plugins that can help you here. Thinking in WordPress made a plugin for WPMU, but I’ve heard it doesn’t quite work yet.

Andrea (and her husband Ron) have a Remove Blog plugin that can also help you.

I’m sure there are others, but I mostly recommend Andrea and Ron’s. And not just because I like them.

Hack

If you’re dead-set on doing this, and you don’t want to use a plugin, there is a manual way to do this. Remember, by doing this you will BREAK the ability of WordPress to check for conflicts between your main site’s urls and any new site. If you’re using SubDirectory SubDomain MultiSite, this should be fine. Hell, I’m doing it. If you’re using SubFolder, I really don’t recommend this at all.

You ready?

  • Login to your admin site.
  • Go to: Super Admin > Sites > Edit
  • Scroll down to “Permalink Structure” and remove the “/blog” part
  • Save

That’s it.

StudioPress Theme of the Month

Comments

  1. Actually, I’m commenting because I wanted to use this smiley.

    :idea:

    • Ipstenu says:

      It’s one of my favorites. I’m actually pretty sure these images AREN’T GPL or open source (which is amusing, cause everything else on the site is…). They’re from my proto plugin ‘Custom Clicky Smilies’ which I want to use to work on MultiSite and BuddyPress, but I’ve not gotten over the hurdle of how to let people replace the icons and not have MY updates over-write them.

  2. Thanks for this great post – totally explained things for me. One question…

    Should this:

    If you’re using SubDirectory MultiSite, this should be fine….If you’re using SubFolder, I really don’t recommend this at all.

    Be this?

    If you’re using SubDomain MultiSite, this should be fine….If you’re using SubFolder, I really don’t recommend this at all.

    In other words, if you are using subdomains or each site has its own domain, you can just use the Admin > Sites > Edit > Permalink method to remove “/blog” and the URL conflicts between sites should not be a problem. Correct?

    And yeah, nice smileys :cool:

  3. You are correct, sir (or madam, as the case may be)! I clearly need a proofreader!

  4. No prob – that’s what were here for! Thx again.

  5. Of note – The hack at the end of this post NO LONGER WORKS.

    I have a new one. Working on it.

  6. Together with this solution http://buddydev.com/buddypress/remove-blog-slug-from-the-default-blog-of-wpmu-subdirectory-installation/ and this plugin http://wordpress.org/extend/plugins/wp-no-category-base/ I somehow got it working with 3.1.

    But I’m not confident that it will last, so I’m eagerly waiting for your solution.

  7. To make it work WITHOUT a plugin …

    1) Go to Network Admin -> Sites
    2) EDIT the main site
    3) Go to the ‘settings’ tab for the main site
    4) Change the permalinks from /blog/%year%/%postname%/ to JUST /%year%/%postname%/
    5) Save

    THE CATCH!

    You can no longer use the normal permalinks interface to edit your permalinks for your main site. This is because /blog/ is hard coded into the permalinks page in wp-admin, so every time you save, it looks to see if it’s there.

    So this is not really a sustainable or tenable solution for your clients, but it can (and will and does) work for 3.1. For now.

  8. Has anybody tried to edit options-permalink.php? I just did! I deleted the lines 65 and 66 on my localhost and testing the result. So far so good.

    • Sure, but editing CORE files is exactly what you DO NOT want to do. Why? Just run and upgrade and forget to document what you did, you will cry.

    • That is true. But until it can be set from the back-end, this solution works for me. I also edit core files from a few plugins and document that, so I’m used to it!

  9. Under WP 3.2.1, nothing worked 100% except, of course, .htaccess. My problem was that I had “migrated” a single-site setup to multisite, and had “old” links without “/blog/” in it. I don’t particularly like them having “/blog/” in it, but I can survive; what I cannot accept is to have broken links :(

    Removing “/blog/” from the settings would break categories, tags, and author links (although the rest — homepage and articles — would work fine). I don’t know if this is related to WP 3.2.1 or just to the particular setup I have.

    So I had to stick to having “/blog/” and to rely on .htaccess for those “old” links…

    • As it happens, you can still do it, I just don’t recommend it as it’s harder and more apt to break. The ‘Hack’ I listed at the end of the post still works on 3.2.x but any time you re-save your permalinks, it reverts back to /blog/

      Any permalinks. On any subsite. You see the problem.

Half-Elf? Try Half OFF WordPress ebooks!