[wp-hackers] Rewrite hacking/recreation

Mark Jaquith mark.wordpress at txfx.net
Mon Jan 29 20:45:23 GMT 2007

On Jan 29, 2007, at 2:51 PM, Eric A. Meyer wrote:

>    I upgraded from WP 1.5.2 to WP2.1 and it broke several of  
> my .htaccess file's rewrite rules.  This has killed two of the most  
> popular feeds on my site, as well as several "index" pages.  I  
> can't seem to properly add a filter to the rewrite_rules_array via  
> a plugin, since it runs on the "Permalinks" admin page with no  
> apparent effect (I know it's running because I threw in a 'die' to  
> find out where it was running) but not on actual URLs in the public  
> site. Basically, I have no idea why things are breaking the way  
> they are.

The rules aren't updated live (on every load)... they're stored in  
the database.   So once your filter is activated, you'll have to  
either manually update your permalink structure in Options >  
Permalinks or have your plugin update it.

The best place to look for learning how the rewrite_rules_array  
should look is at your rewrite_rules option.

<?php var_dump(get_option('rewrite_rules')); ?>

Also keep in mind that it's generally better to have your more- 
specific custom rules inserted first... so don't append to the end of  
the array -- stick it at the front.

Next, you use the query_vars hook to add your custom query var:


This enable you to access it with get_query_var()

I pasted some basic rewrite-fu code here:


> (For that matter, I can't tell why WP needs to re-implement  
> mod_rewrite, but since I'm now stuck in 2.x land, that's pretty  
> much blood over the dam.)

Basically, because not everyone has it, and it was a pain having to  
support a internal rewriter AND mod_rewrite.  Lowest common  
denominator.  We don't have to support both and plugins don't have to  
support both.

That said, if you're serving the alternate feed by passing a special  
GET switch to your regular feed, and you're not worried about  
portability to non-mod_rewrite-enabled hosts, you might still be able  
to keep a hardcoded mod_rewrite rule in .htaccess, provided that it  
is put BEFORE the WordPress block.

As an example:

RewriteRule ^rss2/full/$ /index.php/rss2/?full=true [QSA,L]

# WP's internal rewriter block goes here

Mark Jaquith

Covered Web Services

More information about the wp-hackers mailing list