On my site, I have my own custom php file that handles URL GET requests. For example, at mysite.com/?burger=WellDone, it will query my db and display a page with all burgers with "WellDone" in the appropriate db field.
What I am trying to do is make it accessible via mysite.com/burger/WellDone, and after 5 hours straight, have been unsuccessful.
I have tried plugins, I have tried rewriting the htaccess, I have tried denying write permission to htaccess, and at current state, I am using a "rewrite" plugin by takien.
Before the plugin, accessing mysite.com/burger/WellDone would just show page not found. Now after entering my regex in (below) in the rewrite plugin, it adds my regex to the beginning of wp_options db rewrite_rules, and when I navigate to mysite.com/burger/WellDone, it now redirects me, but to the index of "mysite.com" rather than to mysite.com/?burger=WellDone.
Here is my regex and match:
^burger/([a-zA-Z0-9_/-/s]+)/?$
index.php?Burger=$matches[1]
As stated above, Entering my URL as mysite.com/?burger=WellDone displays perfectly as expected, but mysite.com/burger/WellDone just loops back to the homepage.
Edit:
Thanks to Welcher, I have added this code to functions.php, but it still redirecting to index:
function add_burger_query_vars_filter( $vars ){
$vars[] = "burger";
return $vars;
}
add_filter( 'query_vars', 'add_burger_query_vars_filter' );
function custom_rewrite() {
$this_burger = get_query_var('burger');
add_rewrite_rule(
'^burger/([a-zA-Z0-9_/-/s])/?$',
'index.php?Burger='.$this_burger,
'top'
); //*/
}
add_action('init', 'custom_rewrite');