Search code examples
regexapache.htaccesshttp-redirecturl-rewriting

Redirect URLs that do not start with specific string


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


Solution

  • 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.