Apache Web Server Forum

I'm having an issue when trying to redirect pages based on their context root. I need to have a maintenance page come up based on a specific context root. (ex. www.builder.com/context1 & www.builder.com/context2 get redirected the the maintenance page but all other contexts don't get rewritten and vice versa) The problem I'm having is, if I use a (! not) to specify not this context root it works fine, but I can't specify the context to be redirected. Any help would be greatly appreciated.

? That's assuming you really do want a 302 temporary redirect. And assuming "context1" and "context2" are entirely different strings; otherwise you would of course say "context[12]". The R flag becomes optional as soon as you add the full protocol-plus-domain, which you should always do with any redirect. 302 is the default.

But really, shouldn't you instead have something like

RewriteRule ^(context1|context2) - [R=503,L]

combined with a nice custom 503 page? Don't be fooled by "R=503". That's just mod_rewrite's way of handling any status code that doesn't have a shorthand label like [F] or [G].

First thank you for your help and sorry for my wording, but yes redirect.

In response to the question about the context roots, yes they are completely different, (ex. iOS, android, blackberry, etc...). The issue was they wanted to use a regular html maintenance page for their regular desktop web browsers users, but wanted to supply a json file to the tablet/smartphone users. The systems are independent from one another ( that is why I said vice versa, Android, iOS might be down for maintenance but not the blackberry or web and sometimes just the web might be down but nothing else).

The reason behind not using the rule below, was just to conform to what the previous admin had left behind (sort of standardising). That format ( RewriteCond %{REQUEST_URI} ) was used when they created their maintenance page, but the rule you gave is pretty much used every where else.

I know your rule will work, I just have to make sure I know all possible contexts that they are using.