Good day.

How to get a category name (or taxonomy) by urla and replace it with another? (you can say 301 redirect)

For example: there is a URL - http://название_сайта/категория-1/casumo-casino-reviews site_name http://название_сайта/категория-1/casumo-casino-reviews should be replaced by http://название_сайта/тут_заменить_на_новую_категорию(категория-2)/casumo-casino-reviews

thank

    2 answers 2

    The easiest way to use the plug-in is Redirection .

    Or functions.php add:

     add_action('init', 'do_rewrite'); function do_rewrite() { add_rewrite_rule('^категория-1/', 'index.php?category_name=категория-2','top'); } 

    But with the subcategory of the replaced category - it will not work, most likely - neither the first nor the second solution.

    • Perhaps the plugin is a good solution, but in my case it is necessary to make it in the template through the condition. - webEugene
    • new customer with plaginophobia? )) - KAGG Design
    • can .htaccess be fixed? - KAGG Design
    • No, it's just that there are a lot of redirects and therefore the most optimal option is to make it in templates. - webEugene
    • site on nginx + is needed in the template through the condition) - webEugene
     $test= str_replace('/test/', '/test-2/', $_SERVER['REQUEST_URI']); $current_url = "http://" . $_SERVER['HTTP_HOST'] . $test; if(stristr($_SERVER['REQUEST_URI'], '/test/')){ header("HTTP/1.1 301 Moved Permanently"); header("Location: ". $current_url); exit(); }