Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

Use negative lookahead:

RedirectMatch permanent (^((?!test).)*)$  https://someserver.com$1
share|improve this answer
    
The redirect of URLs that does not have "test" in it results in 404..I guess the redirect isn't working properly... –  Abhishek Mar 22 '12 at 1:40
1  
try this ^(((?!test).)*)$ result of this redirection is: somesite.com/test/me = somesite.com/test/me, somesite.com/folder/me = anothersite.com/somesite.com/niodest/me –  yadaya Mar 22 '12 at 6:45
    
I think what I would want is - everything that does not match somesite.com/test or somesite/test.... followed by anything to be redirected to their https equvalents(eg somesite/nontest to somesite/nontest..) –  Abhishek Mar 22 '12 at 7:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.