Multiple redirects with .htaccess


I have a WordPress site with a Permalink of /%category%/%postname% of over 350 blog posts and I want to change it to just postname /%postname%

I have a few questions.

Is there any quick way to do the redirects? So say I have a category of “fruits” could I put something in the htaccess that would redirect all posts that were originally to

And, secondly, it is bad to have too many redirects in an htaccess file? Would 350 slow down the site?

If the postname is staying the same, you’d just need one rule per category to do the redirects - i.e. /category/postname -> /postname - the rule would jsut throw away the category.

Thank Tim. So redirects in .htaccess like this:

redirect 301 /fruits/
redirect 301 /vegetables/

… where “fruits” and “vegetables” are categories will redirect all the individual blog posts from category/blogpost to /blogpost.

Not quite, as that just redirects the category level but nothing under it. What you’d need to use instead is RedirectMatch, i.e.



And of course make sure there aren’t any posts called “fruits” or “vegetables” etc, as those would get redirected as well.

Really appreciate you help of this one, Scallio and TimIgoe. I couldn’t find this information out by Googling.

Here’s what I used and it worked:

RedirectMatch /categoryname1/(.)$1
RedirectMatch /categoryname2/(.
RedirectMatch /uncategorized/(.*)$1

Excellent, glad it worked :slight_smile: