0

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.

5
  • Where in functions.php are you adding this rewrite rule? Commented Jun 26, 2013 at 8:30
  • using 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; } Commented Jun 26, 2013 at 8:38
  • Hmm, but you don't have this book-page rewrite rule in this code. Commented Jun 26, 2013 at 8:40
  • yes ... it should be '$newrules['(book-page)/(\d*)$']', but it still does not work. Commented Jun 26, 2013 at 8:56
  • 2
    Could you update your question so that it shows how your code looks exactly? In question you're using add_rewrite_rule function, in comment you're using rewrite_rules_array hook and different rule. It's hard to tell what's wrong with your code, when you're not showing it... Commented Jun 26, 2013 at 9:00

1 Answer 1

0

The Yoast SEO wordpress plugin is the culprit in this case. It was redirecting all rewrite urls to the base url. You can turn it off in the plugin settings page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.