.htaccess redirection subdirectory to other ERR_TOO_MANY_REDIRECTS

Viewed 49

I need redirects from a subdirectory to go to the root, example:

example.com/test/aaa

example.com/test/bbb

We need redirect to example.com/test

I have created the next redirect:

Redirect 301 example.com/test/aaa example.com/test/

And I'm getting ERR_TOO_MANY_REDIRECTS error

What is the best solution for this problem? Like example.com/test/# go to example.com/test/

1 Answers

Use RedirectMatch with a regex to be able to match both sub-directories in same rule:

RedirectMatch 301 ^(/test/)(?:aaa|bbb) $1

Make sure to clear your browser cache before testing.

Related