I did not test this, but this should do what you want. Put the following in your functions.php:
add_filter('rewrite_rules_array', 'new_category_name_rewrite_rule');
function new_category_name_rewrite_rule($rules) {
$new_rules = array();
$categories = get_categories();
foreach ($categories as $category) {
$cat_name = preg_replace('#\s+#', '-', $category->name);
$new_rules["https://wordpress.stackexchange.com/".$category->slug."https://wordpress.stackexchange.com/"] = "https://wordpress.stackexchange.com/".urlencode($cat_name)."https://wordpress.stackexchange.com/";
}
return $new_rules + $rules;
}
Related Posts:
- Mod_Rewrite to show only last subcategory in URL
- How do I use the same post slug for different Categories?
- Plural Category Base Slug On Category Archive Page
- Duplicate Category and Page URL loads Category instead of the Page
- wordpress sub-category ( lowercase letters + non-latin characters ) = 404
- The default code for “posts_nav_link” on category.php isn’t working
- Read GET parameters in APACHE Mod Rewrite rules for WordPress categories in Posts
- Removing subcategories from permalinks [duplicate]
- A different permalink structure for different categories
- How to remove category name for only one category?
- Include a page’s “category” in its URL
- Hide category name using mod_rewrite
- hierarchical taxonomy in permalinks? using same slug
- How to get category slug link? ( include parent categories)
- How to add custom prefix before category base for category page URL?
- Custom permalink structure leads to be 404 on pagination
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- Rewrite rule page url with category
- How to remove category from wordpress url?
- How to create a custom url for a category [closed]
- How to change the category in URL for posts in multiple categories?
- How to get the url to tag & category base set by the user?
- How to Include the Parent and Child Category in the Permalink if the Post is Added to Both
- Root level category, tag, author and archive pages to work
- I use same slug name for category and page
- Categories and Tags returning 404 on the sidebar when using ugly permalinks
- Add custom taxonomy terms to WordPress menu dynamically & append #slug to url
- Archive pagination causing 404 with permalinks structure
- WooCommerce change category url and product base
- Removing category base form links messes up the parent-child behavior
- Put a link to a category round a hard coded A HREF
- Category slug $_SERVER[‘REQUEST_URI’];
- 403 forbidden on one page only
- How to set up Author archives with sub category URL
- Get the name an the description of a link category
- WooCommerce duplicate sub categories and product slugs
- How to Filter categories in the permalink structure
- Specifying multiple categories in URL (permalink)?
- Add “page-a” slug to category link if user visit category link from “page-a”
- Redirect category to url with /category
- Changing permalink from /postname/ to category/postname/
- Pagination for category slug returns 404 when page >= 2
- Displaying a full post instead of a slug per category?
- One Specific Category To Permalink
- Category being displayed without base parmalink
- Removing post category base giving Error 404
- Permalinks: display just one kind of wp category in the posts url
- Multiple URL’s based on category for one post
- Same base for category and post
- category permalinks
- A single category with a specific permalink structure differing from the standard set for the rest of the site
- Remove the parent name from permalink
- Redirect single article permalink to paginated category page
- Hide the word ‘category’ from my permalinks
- Automatically redirect a page to a category that share the same slug
- WordPress alphabetical A-Z custom post type post result display
- Hierarchical permalink structure for posts showing categories and sub-categories
- Function to automatically rename the base category permalink
- How to remove one specific category (uncategorized) from post permalinks
- Custom Permalink with child categories creating 404
- How do I retrieve the category ID (ugly permalinks) in my sub-navigation menu?
- Redirect year month day postname permalink structure to category postname structure
- category link not working for a specific slug, works for others
- Ordering categories by slug vs. name
- url for posts for a date within a category
- prefix to post permalinks without affecting category permas
- Category URL Management
- Need help with major category and permalink re-organization
- How to use category slug with a regular page
- Using custom structure prefix showing 404 for sub-categories
- How to add tags under categories
- Different post slug based on archive
- Allow two posts (from different categories) to have the same slug
- How Can I Use Equal And Question Mark In Category Slug?
- Subcategories randomly not working after page/post/category edit in wordpress. Fix: saving permalinks twice
- How to prevent WordPress from redirecting single page to prefixed category archive with same name?
- Category URL’s 404 after setting category base to ‘.’
- How to 301 redirect from url with post id to permalink with post name (slug)?
- Remove “category” from permalink with add_rewrite_rule
- Change the full slug for a specific category?
- Get category from slug list
- Change Category Base For Custom Post Type or Posts Page
- When category name and title are the same … WP will select archive.php instead of single.php
- Accessible Subcategory URL’s pages without using .php hack
- same permalink for parent category and child category
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- Create monthly archive for parent category
- Change category base based on category
- Allow duplicate permalink slugs for posts in different categories
- woocommerce – products by category slug? [closed]
- Most efficient use of custom taxonomies, categories, and pages
- Removing short versions of category archive URL
- How to include first assigned category in the post URL?
- how wordpress generates permalinks as /%category%/%post%/
- Category archive page has two URLs even when default theme is active with no active plugins
- Use same wordpress category base and tags as the prefix as the post permalink
- WordPress how to remove parent slug from category URLs
- Display last category child in permalink
- Using same term for slug and category
- How do we ReWrite HTACCESS to point a cat/subcat Product URL, to Cat/ only?