Reduced Rewrite Plugin

The alternative rewrite rules I mentioned back in October can now be had in plugin form. The Reduced Rewrite plugin replaces the default rewrite rules with a reduced set that simply passes URIs along to WP’s internal rewrite handler. Handling the URIs in this way means that you do not need to make your .htaccess writable once the reduced rules are in place. With these rules, .htaccess does not need to be updated if the permalink structure changes or if new rules are added. The reduced rules also work around several annoying bugs in the mod_rewrite shipped with Apache 1.3. If you have trouble using %category% in your permalink structure, try these rules.

The disadvantage to the reduced rules is that they match everything under your blog directory. If a request is made for /this/dir/does/not/exist/, the server will not 404. Instead, the request is passed to WP and WP issues a 404 to the client. You won’t see a 404 in your server logs, however. If you have to see those 404s in the logs, don’t use the reduced rules.

After activating the plugin, update your permalink structure on the Options->Permalink page to get the new rules.


The plugin now supports two ways of redirecting from mod_rewrite to WP. The first way passes path info to WP. The rewrite rule looks like this:

RewriteRule ^(.+)$ /index.php/$1

The second way uses WP’s internal 404 handler instead of path info. The 404 handler will try to parse the permalink from the requested URI.

RewriteRule . /index.php?error=404

Set a flag in the plugin two switch between the two styles. If your server does not allow path info, use the 404 handler.

18 thoughts on “Reduced Rewrite Plugin

  1. I found your plugin stil not working when requesting a paginated post page (i.e. /catname/postname/2). (Apache 1.3)

    I have the permalink structure : %category%/%postname%.
    This because the greedy first backreference ^([/_0-9a-z-]+) which captures both ‘catname/postname’ and category_name=$1
    Leave out the / and change to ^([_0-9a-z-]+) it isn’t greedy anymore.
    and works.
    The forward slash is allready in the RewriteBase ( i.e RewriteBase /Somefolder/ )

    gr. Ben ter Stal

  2. That slash is there to support subcategories. Removing it will break subcategory permalinks to posts containing subcategories. But, as you noted, the regular expression is still too greedy as long as that slash is present. Subcategory support is the cause of all this grief.

  3. It’d be nice if the plugin implemented an apply_filters that would allow others to extend/modify what was generated.
    Something like: rewrite_pre & rewrite_post.

  4. Do you have any examples of this working anywhere?

    Where it works on Apache 1.3.x and allows for category in permalink structure…

    I have tried this, and still cannot get it to work.

  5. heather, I’ve used Reduced Rewrite on 1.3 installlations with %category%. It doesn’t seem to be working for everyone, however. I don’t know what’s causing it to fail.

    DrBacchus, mod_rewrite in Apache 1.3 doesn’t support the reluctant modifier and can be very picky about how characters in a character class are organized.

    Creating a set of rewrite rules that accommodates as many permalink structures as possible, supports subcategories, supports i18n, and works across all versions of mod_rewrite and php is challenging.

  6. ok- so at least i can have some relief.

    what i’m reading is: “forget about it, it’s not working, get over it, move on”

    thanks for your time though.

  7. I poked around the web, and found a number of places that made this same claim – that the “reluctant modifier” doesn’t work in Apache 1.3 mod_rewrite, and that this modifier is indeed what they are calling the ? modifier.

    Since this is not true (mod_rewrite has supported the ? modifier since the initial releases back in 1995 or so) I’m left wondering whether either some third-party distribution of Apache (like, some Linux distro, say) introduced a bug in the PCRE libraries, or whether there’s some confusion as to what ? is supposed to do, or some other problem that I’m not thinking of.

    My interest in this issue goes a lot farther than permalinks in WordPress, since I’m rewriting the mod_rewrite documentation, as well as working on a book about mod_rewrite. So I’m anxious to find out stuff like this, particularly if it means that I’m the one that’s misinformed.

    Any specific details you could provide regarding exactly what way this modifier fails to work on 1.3 would be enormously appreciated.

  8. Usage of the reluctant modifier, ‘?’, with Apache 1.3 resulted in 500 errors . We recevied many bug reports from Apache 1.3 users when we introduced this into the nightly builds many months ago. Those same nightly builds had no problem using the modifier when running on Apache2.

  9. Ok. Reduced Rewrite corrected almost all my problems and I thank you a lot for that. Bu it created a little regression. The search box does not operate correctly from permalinks and other archived pages. Is there a workaround for this ?

  10. “Set a flag in the plugin two switch between the two styles. If your server does not allow path info, use the 404 handler.”

    Flag? Plugin two switch? Translation for nongeeky person please. This plugin is doing SOMETHING, since I now get my customized 404 page, which I didn’t before. I’d rather get my permalink pages (and a working search box with it, please!)

    apache1.3.33 unix on a linux server
    kernel 2.4.26
    php 4.3.10
    mysql 4.0.22 std

  11. I found that this plugin doesn’t work if you have nested categories, and use %category% in your permalink.rnrnI wrote a plugin that creates a new rewrite handler (wp-htaccess.php) and directs “greedy” requests through that file. It can be found at:rn

Leave a Reply