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?
- Remove parent category from permalink? Basically only have the child category?
- Custom permalink structure leads to be 404 on pagination
- How to get permalinks with category base working with sub-categories
- Use category base slug in posts’ permalink
- Category archive by year with permalink support /category/YYYY
- Add a URL prefix to permalinks of one category of posts only
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- Filtering categories in the permalink structure
- Allow duplicate permalink slugs for posts in different categories
- Force WordPress to Show Pages Instead of Category
- How do I get the category URL from get_the_category?
- Rewrite rule page url with category
- How to remove category from wordpress url?
- Multiple post categories – single permalink
- How to create a custom url for a category [closed]
- How to use category slug with a regular page
- Using custom structure prefix showing 404 for sub-categories
- pagination 404 error, same slug home and categories
- How to add tags under categories
- Different post slug based on archive
- Allow two posts (from different categories) to have the same slug
- OK to redirect the root WordPress category slug?
- How Can I Use Equal And Question Mark In Category Slug?
- How to set the same base url for two different taxonomies?
- Subcategories randomly not working after page/post/category edit in wordpress. Fix: saving permalinks twice
- Get multiple category names from permalink
- How to prevent WordPress from redirecting single page to prefixed category archive with same name?
- Get category base permalink
- Is it possible to set up blog categories without changing permalink structure
- Remove WP Core canonical for category pagination
- Category URL’s 404 after setting category base to ‘.’
- Wrong category in URLs accepted like the correct one
- How to 301 redirect from url with post id to permalink with post name (slug)?
- Using the slug of a custom post category as prefix for the underlying custom post slugs
- Subcategory Page 404ing
- Remove “category” from permalink with add_rewrite_rule
- Change the full slug for a specific category?
- Get category from slug list
- Remove base category gives 404 error
- Custom permalink /%category%/%postname%/ produces 404 on each post
- 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
- WordPress Category url redirects to subdomain
- Accessible Subcategory URL’s pages without using .php hack
- WordPress and “pretty permalink”
- How to auto update post title and slug with category name when post status is updated
- same permalink for parent category and child category
- Get full control over custom post type url
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- Show only one of the categories of a post in the breadcrumb?
- Group Posts by First Letter of Title categories
- /blog/ permalink prefix causes category pages to 404
- Create monthly archive for parent category
- Using categories and pages in menus
- Page Type with Category Link
- Change category base based on category
- Allow duplicate permalink slugs for posts in different categories
- woocommerce – products by category slug? [closed]
- Changing Permalinks for Category Pages Only
- Most efficient use of custom taxonomies, categories, and pages
- Category slug in in loop always the same?
- Removing short versions of category archive URL
- Link categories to last post
- Change next_post and previous_link to navigate throught parent categories only
- Using pagination with multiple loops causes it to break
- How can I get rid of the the category suffix–NOT “prefix” (i.e. foo-1, foo-2, etc)
- How to include first assigned category in the post URL?
- How do I hide posts in a category from all listings but still allow the posts to be viewed?
- how wordpress generates permalinks as /%category%/%post%/
- Create custom Perma link
- Multiple Parent Category URLs
- Custom permalinks structure
- Category archive page has two URLs even when default theme is active with no active plugins
- Custom EndPoint not working when strip child category in URL
- Remove “?category=” in the URL wordpress ajax filter work for category
- Use same wordpress category base and tags as the prefix as the post permalink
- WordPress how to remove parent slug from category URLs
- How to remove the category from the url only for a specific category of articles on wordpress
- category id (term_id) in url instead of slug
- Display last category child in permalink
- Disable Category Link
- Link from page to category posts
- Using same term for slug and category
- How do we ReWrite HTACCESS to point a cat/subcat Product URL, to Cat/ only?
- Changing category base slug results in 404 errors on posts?