I’m adding rewrite rules to my PHP script which is included in a WordPress page with the permalink kb
So I can visit domain.com/kb and the page is displayed.
function wdm_add_rewrite_rules() {
add_rewrite_rule( '^kb/([^/]+)/?$', 'kb?kb_cat=$matches[1]&kb_seq=1', 'top');
}
add_action('init', 'wdm_add_rewrite_rules');
But when I visit the page with additional strings in the url, I get a 404.
So when I visit domain.com/kb is shows the correct page, and then visiting domain.com/kb/84/92, it shows a 404
I just need to be able to read the additional url params in my PHP script, such as $_GET["kb_cat"]
2
Answers
try this:
You can check the regular expression on https://regex101.com/ or any other websites like this online for the matches
to take it a step further and use the parameters:
and then load a custom template file:
Once adding to your
functions.php
go to Settings > Permalinks and hit ‘save changes’ to reset the flush rules