I am trying to integrate a few non-wordpress PHP pages into an existing WordPress site. Ideally, I want to rewrite anything request that looks like this: ‘domain.com/books/bookname’ to ‘domain.com/catalog.php?title=bookname’. I have been messing around with the WP Rewrite API for several hours, but I just can’t get anything to work. Here is my current plugin code:
register_activation_hook( __FILE__, 'wbm_catalog_activate' );
function wbm_catalog_activate() {
wbm_catalog_add_rules();
flush_rewrite_rules();
}
// Flush when deactivated
register_deactivation_hook( __FILE__, 'wbm_catalog_deactivate' );
function wbm_catalog_deactivate() {
flush_rewrite_rules();
}
add_action( 'init', 'wbm_catalog_add_rules' );
function wbm_catalog_add_rules() {
add_rewrite_rule( 'books/([^/]+)/?',
'catalog.php?title=$matches[1]', 'top' );
}
I can even inspect the $wp_rewrite object and see my new rule added, but whenever I try to visit a rewritten url, wordpress acts as though the rule were not there.
I have been banging my head up against a brick wall, and I would appreciate any help you could give!
I was unable to ever resolve this issue. The site that I was working on was part of an old WordPressMU setup (2.8) with a number of sites. I did not have access to the .htaccess that the MU install was using, and it was not passing any requests through to the .htaccess file that I could edit.