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
add_rewrite_rule('^ads.txt/', 'ads.txt', 'top');
won't work the way you think it will, the second parameter must always be some form ofindex.php
– Tom J Nowell♦ Sep 26 '17 at 16:17