WordPress category page redirects in .htaccess not working

Once you have found the right .htaccess file in the document root (ie. inside the public_html directory) then these redirect directives need to go at the top of the .htaccess file, before the existing WordPress directives. ie. Before the # BEGIN WordPress section.

You do not need to repeat the RewriteEngine or RewriteBase directives. (The RewriteBase directive is not actually being used here anyway.) The RewriteEngine On directive appears later in the file (inside the WordPress block), you do not need to repeat this.

To redirect as required you just need the following:

RewriteRule ^category/microgreens/recommended-equipment/ https://www.planthardware.com/microgreens-equipment/ [R=301,L]

You do not need the capturing subpattern (.*) and corresponding $1 backreference to redirect the example URL as stated.

NB: Test with 302 (temporary) redirect first to avoid potential caching issues.

If you are redirecting to the same scheme and hostname, you do not need to repeat these in the target URL. For example:

RewriteRule ^category/microgreens/recommended-equipment/ /microgreens-equipment/ [R=301,L]

You can use capturing subpatterns and backreferences to avoid repetition. For example:

RewriteRule ^category/(microgreens)/recommended-(equipment)/ /$1-$2/ [R=301,L]

The $1 backreference contains “microgreens” from the first capturing group (parenthesised subpattern) and $2 contains “equipment” from the second.


UPDATE: And for the second redirect you could write it like this (using backreferences):

RewriteRule ^category/(microgreens)/(growing)/ /$1-$2/ [R=301,L]

To redirect to /microgreens-growing/.


Aside:

I’ve also tried putting the following in .htaccess and it doesn’t work:

RedirectPermanent https://www.planthardware.com/category/microgreens/recommended-equipment/ https://www.planthardware.com/microgreens-equipment/

Note that the RedirectPermanent directive belongs to mod_alias (as opposed to mod_rewrite RewriteRule), consequently it runs much later, after all the other mod_rewrite directives, despite the apparent order of the directives in the config file. For this reason, it is advisable not to mix redirects from both modules, since you can get unexpected conflicts.

Note that the RedirectPermanent directive matches against the root relative URL-path (starting with a slash), not the absolute URL. So, the above directive wouldn’t match anyway. It should be written like this instead:

RedirectPermanent /category/microgreens/recommended-equipment/ https://www.planthardware.com/microgreens-equipment/

OR (omitting the scheme + hostname on the target URL):

RedirectPermanent /category/microgreens/recommended-equipment/ /microgreens-equipment/