Apache directive to not to redirect REQUEST_URI with IF condition

1.1k views Asked by At

The Apache directive is working successfully to redirect the web application URL if it contains "/login" string in REQUEST_URI to the help page. This works with a single directive as below.

RedirectMatch 301 "^(.*)" "https://x.y.com/help-url/"

However, I wanted to not to redirect to help page if "REQUEST_URI" contains string login?next=/scm

I modified/added directive as below however it is not working as expected.

<LocationMatch "^/login">
    <If "%{REQUEST_URI} =~ m#/scm#">
        #Do nothing
    </If>
    <Else>
        RedirectMatch 301 "^(.*)" "https://x.y.com/help-url/"
    </Else>
</LocationMatch>
1

There are 1 answers

2
Daniel Ferradal On

Why not just?

RewriteEngine on
RewriteCond %{QUERY_STRING} !^next=/scm$
RewriteRule ^/login.+?/scm https://x.y.com/help-url/ [R,L]

We check if good query string is not sent, in that case we perform the redirection for the path you want to check to the help url.

Note should you need different checks you can add rewriteconds there as necessary