Rewrite rule to index.php in theme subfolder
Question
I’m trying to create a rewrite to an index.php in a subfolder of my theme. But with this code I only end up on the front page:
function coupon_query_vars( $query_vars ){
$query_vars[] = 'gutschein';
return $query_vars;}
add_filter('query_vars', 'coupon_query_vars');
function add_coupon_rewrite_rules($rules) {
$theme_name = next(explode('/themes/', get_stylesheet_directory()));
$newrules = array(
'^gutschein-pdf/([^/]*)/?$' => 'wp-content/themes/'. $theme_name . '/pdf/?gutschein=$matches[1]',
);
$rules = $newrules + $rules;
return $rules;}
add_filter('rewrite_rules_array', 'add_coupon_rewrite_rules');
The nice url looks like:
https://domain.com/gutschein-pdf/coupon_hb0j9f/
And it should redirect to:
https://domain.com/wp-content/themes/themename/pdf/?gutschein=coupon_hb0j9f
What do I have to change on the this rule?
0
2 months
2022-11-25T10:38:14-05:00
2022-11-25T10:38:14-05:00 0 Answers
0 views
0
Leave an answer