[wp-hackers] Creating custom rewrite rules

Callum Macdonald lists.automattic.com at callum-macdonald.com
Mon Feb 19 05:02:50 GMT 2007


G'day,

Does anyone have a copy of the Custom Rewrite Rules plugin? The download 
link is dead.
http://wp-plugins.net/plugin/custom_rewrite_rules/

If not, I'm reading the WP_Rewrite function reference on codex:
http://codex.wordpress.org/Function_Reference/WP_Rewrite

and using the FeedDirector plugin as a starting point:
http://boren.nu/archives/2005/03/29/feed-director-plugin/

I'd like to add some custom rewrite rules to redirect 
/directory/pagename.htm to page_id = 2. Does that make sense? So 
siteurl.com/directory/pagename.htm will load the page with page_id 2 in 
WordPress.

I've tried this code (modified from the Feed Director plugin:
function feed_dir_rewrite($wp_rewrite) {
    $feed_rules = array(
        'index.rdf' => 'index.php?feed=rdf',
        'index.xml' => 'index.php?feed=rss2',
        'test.htm' => 'index.php&page_id=2',
        '(.+).xml' => 'index.php?feed=' . $wp_rewrite->preg_index(1)
        );

        $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
}

The index.rdf and index.xml links work, but my test.htm link doesn't for 
some reason. Can anyone offer any suggestions?

Cheers,


Callum.



More information about the wp-hackers mailing list