help to remove last trailing slash using add_rewrite_rule
Question
I already tried in several ways to remove the last slash of the url that I created with add_rewrite_rule
.
below is the implementation of my code
function master_load_ads_txt_template_include($template) {
$is_load_ads_txt = (bool)get_query_var('ads-txt');
if( $is_load_ads_txt ) {
$template = get_template_part("template-parts/ads-txt");
}
return $template;
}
add_action( 'template_include', 'master_load_ads_txt_template_include' );
function master_load_ads_txt_rewrite() {
add_rewrite_rule('ads.txt', 'index.php?ads-txt=true', 'top');
add_rewrite_rule('^ads.txt/', 'ads.txt', 'top');
}
add_action('init', 'master_load_ads_txt_rewrite');
function master_load_ads_txt_query_vars( $query_vars ) {
$query_vars[] = 'ads-txt';
return $query_vars;
}
add_filter( 'query_vars', 'master_load_ads_txt_query_vars');
the code is working but does not remove the slash at the end of the url
0
permalinks, rewrite-rules, url-rewriting
5 years
2017-09-26T09:44:25-05:00
2017-09-26T09:44:25-05:00 0 Answers
81 views
0
Leave an answer