Tomcat – RedirectMatch redirect every url to https except few urls

apache-2.2httpdmod-proxyredirecttomcat

At present I am redirecting all http urls to https urls using the following directive,

RedirectMatch permanent ^(.*)$ https://someserver.com$1

Now I am stuck with an scenario where I have to redirect everything except the URLs like http://someserver.com/test or http://someserver.com/test/users or basically anything that has a /test followed by anything in it.

Also, I want to redirect these urls that have a "/test.." to be a normal http to show an access denied page(a html page). To add on to the complication all requests that go through "/" are routed to tomcat via ajp using the <Location /> and ProxyPass directives

I am forced to use only RedirectMatch in this case basically because if I have to use Rewrite I have to change a lot of other configurations.

Could we have multiple RedirectMatch? If so, how can I configure the regex for the scenario above…

Best Answer

Use negative lookahead:

RedirectMatch permanent (^((?!test).)*)$  https://someserver.com$1