I am following the WP Example. I know my rewrite rule is being added into wordpress, so I just need to fix the actual rule. So here is my current code:
add_filter('rewrite_rules_array','mcs_TextbookRewriteRules');
add_filter('query_vars','mcs_insertTextbookQueryVars');
// Adding a new rule
function mcs_TextbookRewriteRules($rules) {
$newrules = array();
$newrules['textbook/(cantonese|mandarin)/([C|M]K?[0-9]+)/([0-9]+)$'] = 'index.php?pagename=textbook/$matches[1]/?cls=$matches[2]&ch=$matches[3]';
//$newrules['textbook/(cantonese|mandarin)/([C|M]K?[0-9]+)/([0-9]+)$'] = 'textbook/$matches[1]/index.php?cls=$matches[2]&ch=$matches[3]';
return $newrules + $rules;
}
// Adding the id var so that WP recognizes it
function mcs_insertTextbookQueryVars($vars) {
array_push($vars, 'cls');
array_push($vars, 'ch');
return $vars;
}
I want to map http://localhost/wordpress/textbook/cantonese/CK1/6
to http://localhost/wordpress/textbook/cantonese/?cls=CK1&ch=6
I see a second
?
in your query variables (before thecls
query variable), probably from experimenting with the commented-out form, I think you want to use&
there.Your
query_vars
hook currently adds theid
variable, but you usecls
andch
in your rewrite rule, so this will not have an effect.If you are changing the rewrite rules I recommend my rewrite analyzer plugin (soon in the repository, but get the current version via Dropbox), it helps you debug these things.