Get Me Rewrite!

Consider this a plea for help:

This site has been through some serious migrations over the years. It’s had two different hosting providers and three different blog platforms, among other kinds of changes. As a result, its permalink structure has changed over time, and I’ve had to use mod_rewrite to grapple with redirecting old inbound links to where they need to go.

By and large, I’ve been able to manage this. I’ve got one big lingering problem, however, that results from neither a server nor a platform migration.

For several years, Planned Obsolescence ran on a single-site WordPress installation, with pretty /%postname%/ permalinks. A little while back, I got the bright idea that I should consolidate it with a few other WP instances I was running, through one clean multi-site installation.

This is now the main site of that multi-site instance. But multi-site WP adds /blog/ to the URLs of all posts in that main site. And so inbound links that are looking for get 404’d.

I have searched around, both within and out in the larger internets, for a way to use htaccess to redirect such inbound links to But I’ve run into several problems, most notably, infinite redirect loops: even when I include a !blog condition in the rewrite rule, the request still gets caught in some redirect vortex. I also need to make sure that a few pages and secondary blog directories don’t wind up with /blog/ added to their URLs.

I’ve created a 404 page that attempts to explain the problem, and I should probably just let it go at that, but knowing all those errors are out there makes my OCD kick in. So if there were a mod_rewrite guru out there willing to help me work through this problem, I’d be enormously grateful.


  1. A few quick questions (apologies if you’ve already tried these…):

    1.) Does the following not work?

    Go to Network Admin -> Sites -> Edit Site (for the main site)
    Find the permalink structure and remove /blog/

    My searching suggests that, so long as you edit that, and not the permalink under the site config (which will then re-insert a mandatory “/blog” slug), it might work…

    2.) Assuming you had already tried that (and the existence of the plugin I’m about to mention suggests that the above can’t be the answer):

    Have you tried the “remove /blog slug plugin for wpmu?

    3.) The .htaccess solution would be problematic, I suspect, because WordPress won’t know which site to serve without a corresponding database entry…


    1. Hi, Martin. I’ve considered those options, but there are reasons that multi-site WP uses the /blog/ slug for the core site — most notably, that it prevents conflicts between core blog post titles and potential secondary site titles. The htaccess solution should not interfere with WP — it should redirect the currently broken URLs to the existing db entries. But it creates all the havoc I described in the post in the process. I may have to go with one of the solutions you suggest here, but neither is really ideal.

      1. Hi Kathleen,

        My apologies for suggesting things already tried – I figured you might have attempted those but would start with the obvious anyway.

        If you are willing to post some relevant parts of the htaccess file I’ll have a think tomorrow.



  2. Hi Kathleen! Kristen Eshleman sent me your way—maybe something along these lines might help?

    RewriteEngine on
    # if it doesn’t exist as a file or as a directory…
    RewriteCond /path/to/docroot/%{REQUEST_FILENAME} !-f
    RewriteCond /path/to/docroot/%{REQUEST_FILENAME} !-d

    # …check whether it exists in /blog
    RewriteCond /path/to/docroot/blog/%{REQUEST_FILENAME} -f

    # and if so then redirect there and stop processing remaining rules
    RewriteRule ^(.+) /path/to/docroot/blog/$1 [L]

    # maybe some other pre-existing redirects in here?

    # otherwise pass the request through unchanged
    RewriteRule ^(.+) – [PT]


    1. Hi, Alex. Thanks for the suggestion! Does this rely on there existing an actual directory named /blog/, with actual files in it, against which requests would be checked? Or does the “whether it exists in /blog” condition include URLs dynamically generated by WP?

  3. I have a very ugly but actually working fix. It requires me to add RewriteCond lines for each sub-blog, which is not currently too onerous, as there are only three of them, but which would require some actual technical solution if I were to expand. But for the record:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/cpfinal/
    RewriteCond %{REQUEST_URI} !^/cpdraft/
    RewriteCond %{REQUEST_URI} !^/infinitesummer/
    RewriteCond %{REQUEST_URI} !^/wp-content/
    RewriteCond %{REQUEST_URI} !^/blog/
    RewriteRule ^(.*)$ blog/$1 [L,R=301]

Leave a Comment

Your email address will not be published.

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