Where’d All My Rewrite Rules Go?

Between WordPress 1.x and 2.x there was a big change to the way rewrite rules are handled.

In the old days, everything got written out to a .htaccess file. Every condition, every form of permalink could be found there, and I had some comfort knowing I could see and mess with it all. I was a bit surprised to find that with 2.0.2, WP writes out a sparse file that has only one significant rule. Something that looks like this:

RewriteRule . /blog/index.php [L]

That one line takes everything in your request URL and passes it through to index.php for processing. The beauty of this is that WP doesn’t need to write to the file system with every change to the permalink structure (which used to include every new “page” added or renamed).

The only downside to this is that you can no longer expect a $_REQUEST array full of all the query terms your plugin might use. Instead you’ll have to use the $wp_query object. All of this was probably mentioned in the API docs before I built a bunch of dependancies on $_REQUEST, but it was easy enough to fix.

$wp_query, $_REQUEST, .htaccess, apache, apache rewrite, rewrite rules, wordpress, wpopac

2 thoughts on “Where’d All My Rewrite Rules Go?

  1. The hell of this is that if you had handwritten rewrite rules that took calls for old pages “hello? is faq.html there?” and sent them to nicers urls like /faq, this is borked in ways I haven’t entirely been able to fix yet. If you know how to speak .htaccess please let me know.

    [tags]htaccess, jessamyn, wordpress, borked[/tags]

  2. Jessamyn: I’m too lazy to actually test this advice, but you’ll want to insert your own rules above the catch-all rule quoted in my post. It should look something like this:

    RewriteRule ^faq/ /blog/faq.html [QSA,L]
    RewriteRule . /blog/index.php [L]

    Then save the .htaccess with your changes and set the permissions/ownership so WP can’t rewrite them.

Comments are closed.