Redirect URLs that do not start with specific stri

2019-07-29 04:25发布

问题:

good day everyone, I'm trying to get a redirection work but i keep getting the error "too many redirects"... I want to redirect all the URLs that do not start with a specific strings, I wrote this and many others but didn't work:

RewriteRule !^(?=string1)(?=string2)(?=string3)/(.*) / [R=301,L]

Is there anything wrong? Thanks

回答1:

You need to exclude the homepage in your redirect:

RewriteRule ^(?!string1|string2|string3|$) / [R=301,L]

However, that will not work until you clear your browser cache. When you do that, it will stop redirecting too many times.