PHP Mod_Rewrite

I commented out the RewriteRule in my .htaccess file and created a new WP_Rewrite rule in my WP theme’s functions.php file. This effectively accomplishes the same thing, but ensures that WordPress is aware of the ‘extra’ querystring variables (so they’re not lost or ignored).

/**
 * Handle URL rewrites for profiles page
 **/
function ctx_rewrite_participant_profiles() {

    //Add the new rule before any other WP rules
    add_rewrite_rule('^participants/profile/([^/]*)/([^/]*)/?','index.php?page_id=83&profile=$matches[1]&title=$matches[2]','top');

    //Let WP know about our custom querystring variables
    add_rewrite_tag('%profile%','([^&]+)','profile=');
    add_rewrite_tag('%title%','([^&]+)','title=');
}
//Hook this into init
add_action('init', 'ctx_rewrite_participant_profiles');

 

Source

http://wordpress.org/support/topic/wp-ignores-querystring-variables-when-using-mod_rewrite

Leave a Reply