0

There are 2000 Custom Taxonomies, called tax_city in my website
https://www.example.com/tax_city/london

and I want to change URL to something like this:

https://www.example.com/services/home-care/london

so, when someone visiting this URL, actually see taxonomy archive page. but with nicer URL.

I know this is possible somehow with htaccess but no idea start from which point.

any guide?

1
  • 1
    "I know this is possible somehow with htaccess" - not with .htaccess (at least, not with WordPress).
    – MrWhite
    Commented May 19, 2021 at 15:39

2 Answers 2

3

You'd be better off adding or modifying the rewrite variable that's being passed to your register_taxonomy() call for the custom taxonomy. You can modify the rewrites to suit your purpose.

For example:

$taxonomy_args = array(
    // All the variables and their values...
    'rewrite' => array(
        'slug' => 'services/home-care',
    ),
    // ...more variables and values...
);

register_taxonomy( 'tax_city', $object_types, $taxonomy_args );

Be sure to flush your site's permalinks after you make the change.

1
  • Thank you, this one worked for me, adding as answer so maybe can be helpful for someone function custom_rewrite_rules() { add_rewrite_rule('^services/(.*)/(.*)?', 'index.php?service_category=$matches[1]&tax_city=$matches[2]', 'top'); } add_action('init', 'custom_rewrite_rules');
    – Amino
    Commented May 20, 2021 at 11:14
1

This one worked for me.

function custom_rewrite_rules() {
    add_rewrite_rule('^services/(.*)/(.*)?', 'index.php?service_category=$matches[1]&tax_city=$matches[2]', 'top');
}
add_action('init', 'custom_rewrite_rules');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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