I want to redirect mywebsite.com/anyname.html to mywebsite.com/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.


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.

  • thank you for the support. But i want to do this in functions.php Sep 14 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.