I have a custom page template to use for a wordpress page. I am trying to setup a custom rewrite rule but without success.
I have a page at blog/book-page/, the display of this page depends on the book id, hence I want url like blog/book-page/book-id/ to read the book id.
In my functions php I have included the below function from Wordpress Codex:
add_rewrite_rule('^book-page/([^/]*)/?','index.php?page_id=11&book_id=$matches[1]','top');
But when I access http://xyz.com/book-page/123/, it keeps on redirecting me to http://xyz.com/book-page/
I refreshed the rewrite rules by saving the permalinks in the dashboard.
Unable to solve by looking at similar questions at: Custom rewrite rule is not picked by Wordpress and https://wordpress.stackexchange.com/questions/91673/need-help-creating-custom-rewrite-rule
Any suggestions, Thanks in advance.
functions.php
are you adding this rewrite rule?add_filter( 'rewrite_rules_array','my_insert_rewrite_rules' ); function my_insert_rewrite_rules( $rules ) { $newrules = array(); $newrules['(generate-photo-quotes)/(\d*)$'] = 'index.php?pagename=$matches[1]&id=$matches[2]'; return $newrules + $rules; }
book-page
rewrite rule in this code.add_rewrite_rule
function, in comment you're usingrewrite_rules_array
hook and different rule. It's hard to tell what's wrong with your code, when you're not showing it...