I moved my wordpress page up a directory and also changed a bunch of categories with new names. But when I try to set a 301 redirect via .htaccess and then access that category url, the browser errors with a "too many redirects" message.

Redirect 301 /category/cat-a/subcat-a/subsubcat-a/ https://example.com/category/newcat-a/newsubcat-a/

Redirect 301 /category/cat-b/subcat-b/ https://example.com/category/newcat-b/mynewsubcat-b/

... bunch more categories

the "category" slug stays the same in the new and old names.

I know there is a flag that makes a rule "final" but I'm not sure how I could make. Cause I also tried setting the flag afterwards like:

Redirect 301 /category/cat-a/subcat-a/subsubcat-a/ https://example.com/category/newcat-a/newsubcat-a/ [L]

I've tried this and many other variations but neither did work out in my favour.

Do I miss something. Im also not sure if there is a regex that solves that problem. Basically from what i've understand, this creates an infinite loop.

1 Answer 1


It's not clear from what you have posted why you are getting a redirect loop. We would need to see the rest of .htaccess file. However ....

You may be getting a conflict with existing mod_rewrite (ie. RewriteRule) directives. Redirect is a mod_alias directive.

You no doubt have existing mod_rewrite directives with the WordPress front-controller. You have other redirects also. You should avoid mixing redirects from both modules since they may not execute in the order you expect (mod_rewrite always runs before mod_alias, despite the apparent order in the config file).

I know there is a flag that makes a rule "final" but ...

That "flag" applies to mod_rewrite RewriteRule, not Redirect (mod_alias). By adding that flag to Redirect in this context it will simply be ignored.

You should change these mod_alias Redirect directives to mod_rewrite RewriteRule and include them at the very top of your file.

For example:

RewriteRule ^(category)/cat-a/subcat-a/subsubcat-a/(.*) /$1/newcat-a/newsubcat-a/$2 [R=302,L]
RewriteRule ^(category)/cat-b/subcat-b/(.*) /$1/newcat-b/mynewsubcat-b/$2 [R=302,L]

This assumes that everything after the categories are copied onto the end of the target URL. eg. .../subsubcat-a/foo/bar becomes .../newsubcat-a/foo/bar. (Which is what your original Redirect directives would have done.)

$1 is a backreference to "category" (simply saves repetition) and $2 is everything after the category string.

The L (last) flag is required here.

Test with 302 and only change to 301 when you are sure it's working OK - to avoid caching issues.

You will need to clear your browser cache before testing.

  • That totaly solved my problem. Although I had a few new categories that had a name other than the wildcard (.*), but i fixed those with a mod_alias. Thanks!
    – Willi
    Feb 1, 2019 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.