0

I have a WP site and need to make all URLs like /fruits/apple/ and /fruits/banana/ lead to the same dynamic page e.g. rewritten as such: /fruit-template?id=apple

At the moment I have created the page /fruit-template using a custom template that handles the query string "id". I have tried WP URL rewriting to accomplish my goal, but /fruits/apple/ always lead to 404.

Am I missing something? Is there another better approach to this need of a virtual page? Or can you suggest a proper rewrite rule that works?

2
  • It seems that you've forgotten flush rewrite cache. In the WordPress administration dashboard on the left-hand side, click “Settings” and then “Permalinks”. Scroll down to the bottom of the page after all of the existing options and click “Save Changes”. Or use flush_rewrite_rules to do it automatically Aug 24, 2017 at 9:14
  • show us what you have tried.
    – Milo
    Aug 24, 2017 at 13:13

1 Answer 1

0

This is what I've tried so far (and a number of experimental variations)

add_rewrite_rule('reviews/([^/]+)/?', 'review-template','top');

I have done flush_rewrite_rules multiple times and verified the changes in .htaccess.

2

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.