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>
Why not just?
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