Where do I USE add_rewrite_rule?
I need to add a RewriteRule to my site. I have tried in .htaccess with no luck, it doesn't get parsed, so I'm all but giving up on that. I found the documentation on add_rewrite_rule, but have no idea where I'm supposed to use it. I am not writing a plugin. I need to put in one simple rule.
I went to the functions.php file in what is the current theme folder. Is this the one I use? I inserted the following:
add_action( 'init', 'add_news_rule3' );
function add_news_rule3()
{ add_rewrite_rule( '^/content/([^/]*)/([^/]*)\.htm$', '/content/$matches[1] [NC,R=301,L]', 'top' ); }
I've also tried, based on a post I saw elsewhere:
add_action( 'generate_rewrite_rules', 'add_news_rule' );
function add_news_rule($wp_rewrite)
{ $new_rules = array('^/content/([^/]*)/([^/]*)\.htm$' = '/content/$matches[1] [NC,R=301,L]');
$wp_rewrite-rules = $new_rules + $wp_rewrite-rules; }
add_filter('rewrite_rules_array','add_news_rule2');
function add_news_rule2($rules)
{ $new_rules = array('^/content/([^/]*)/([^/]*)\.htm$' = '/content/$matches[1] [NC,R=301,L]');
return $new_rules + $rules; }
Topic rewrite-rules Wordpress
Category Web