'Rewriting taxonomy URL from ID to slug

I'm trying to rewrite the URL for my wordpress website to be more user and SEO friendly. But I'm not sure about the rewrite rule I should add to the .htaccess file.

Basically, I want to rewrite this: https://www.mywebsite.com/city/london/?cat_id=123 to: https://www.mywebsite.com/london/mobile-phones

Both "london" and "mobile-phones" are taxonomies here.



Solution 1:[1]

You have to write a 301 redirection as:

redirect 301 /city/london/  https://www.mywebsite.com/london/

since in the second URL, there is no 'city' slug.

Also please try this method for the URL rewrite:

RewriteRule ^london/(.*)/ wp-content/themes/mytheme/single-mycategory.php?cat_id=$1

Then in that single-mycategory.php file, you can fetch the cat_id and display the data associated with that category.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Roby Raju Oommen