admin管理员组

文章数量:1287934

I want to redirect mywebsite/anyname.html to mywebsite/product/anyname For that I write the following query in functions.php . But it is not working . Please see my code below

function custom_rewrite_basic() {
  add_rewrite_rule('^(.*)\.html$', '/product/$1');
}

add_action('init', 'custom_rewrite_basic');

Please help to solve the issue.

I want to redirect mywebsite/anyname.html to mywebsite/product/anyname For that I write the following query in functions.php . But it is not working . Please see my code below

function custom_rewrite_basic() {
  add_rewrite_rule('^(.*)\.html$', '/product/$1');
}

add_action('init', 'custom_rewrite_basic');

Please help to solve the issue.

Share Improve this question edited Sep 14, 2021 at 6:54 Abilash Erikson asked Sep 14, 2021 at 6:51 Abilash EriksonAbilash Erikson 1251 silver badge10 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 1

Or you could just add the relevant directive to the top of the .htaccess file directly. For example:

RewriteRule ^([^/]+)\.html$ /product/$1 [R=302,L]

This matches /anyname.html (as in your example), but not /foo/bar/anyname.html.

本文标签: url rewritingaddrewriterule fro html to another url not working