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.

I have website content like

mysite.com/index.php

mysite.com/apps

Now I want to put a maintenance page so people who will visit to mysite.com or mysite.com/index.php will able to see maintenance page however visitors will go to mysite.com/apps or mysite.com/apps/index.php will not redirect to maintenance page.

I already tried these:

This is redirecting both root and subfolder to maintenance page.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
RewriteRule ^(.*)$ http://mysite.com/maintenance.html/$1 [R=301,L]

This is not doing anything

RewriteEngine on
RewriteCond %{HTTP_HOST} mysite\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://mysecondsite.com/ [L,R=301]
share|improve this question
    
Did you want to redirect to the maintenance page or the second site? –  Shane Madden May 12 '12 at 3:15
    
No Shene, I want redirect root index.php to maintenance page but not sub directories –  Sandy Fark May 12 '12 at 6:09
add comment

2 Answers

According to the HTTP Spec the correct response to return would be a 503 Service Unavailable, and you should do this from / rather than redirecting.

You could use Bittrance's solution, it should work, although you might want to separate out the rules since you'll probably want to redirect index.php to / in the long run.

I would certainly discourage using a 301 redirect to point to a maintenance page, that would indicate that it is a permanent redirect rather than maintenance, if you must do a redirect I'd recommend using a 302.


To summarise, I think the best solution would be to 301 redirect index.php to / since you'll want that anyway, and whilst you're performing maintenance, / should return a 503 (and you can still have a nice maintenance page there), it's just your PHP's job to serve it not htaccess.

share|improve this answer
add comment

Not sure I understand your question. Is there some reason you can't do:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
RewriteRule ^(|/|/index.php)$ http://mysite.com/maintenance.html/ [R=301,L]

... or some similar limited rerwriterule?

share|improve this answer
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.