views:

381

answers:

3

I was trying to install this .htaccess to notify my users of site maintenance. It seems the first [L] isn't working and the second rewrite is doing everything.

How do you guys do site maintenance messages?

RewriteEngine on

RewriteRule ^s/down$ index.html [L]
RewriteRule ^(.*)$ http://metaward.com/s/down [R=302,L]
+1  A: 

The RewriteRules I'm using on my website when I want to shut it down for maintenance are these ones :

RewriteCond %{REMOTE_ADDR} !=MY_IP_ADDRESS
RewriteRule    ^$  /down.html  [L]
RewriteCond %{REMOTE_ADDR} !=MY_IP_ADDRESS
RewriteRule    [^/down.html$]  /down.html  [L]

(Maybe not quite "optimized", I should say... But it worked (or so it seemed) each time I used those)

Everything but down.html gets redirected to down.html -- except for me, of course : I want to be able to test the maintenance operations I'm doing, obviously

ANd when I'm finished, I just comment those four lines.

Pascal MARTIN
The IP address condition: neat.
Ölbaum
won't that make search engines index your page as if it was perfectly up but serving your weird down page?
Paul Tarjan
@Paul : I have to admit I don't know for sure ; I've put <meta name="robots" content="noindex, follow" /> in down.html as a security measure, but I'm not sure what a bot would do : I've never seen the content of my down.html page on google, that's for sure, and I've never noticed anything "bad" for the other pages ;; but my maintenance operations are rare, and never lasted more than 3 hours ;; and my website is not big/famous, so not indexed too often... ;; Still, if someone sees a way to make this better, I'm definitly interested (would be nice to provide an answer, and get one myself !) ;-)
Pascal MARTIN
A: 

You don’t need to an external redirect. Just send the 503 status code and your error document.

RewriteCond %{ENV:REDIRECT_STATUS} !=503
RewriteRule !^s/down$ s/down [L,R=503]

But you need Apache 2.x to use a different status code with the R flag other than 3xx.

Gumbo
503 won't actually cause the browser to redirect.
Paul Tarjan
@Paul Tarjan: I’ve never said that. Apache 2 just extended the use of the `R` flag for setting status codes. Only 3xx status codes will actually cause an external redirect.
Gumbo
interesting, so the R doesn't actually force a redirect? wow, testing..
Paul Tarjan
Setting [R=503] shows a default apache page not the one I specified in my RewriteRule. Is this the expected response?
Paul Tarjan
A: 

This seems to work (but I have to set the status code in PHP)

RewriteEngine on

RewriteCond %{REQUEST_URI} !^/static/.*$
RewriteCond %{REQUEST_URI} !^/media/.*$
RewriteRule .* down.php [L]

and in down.php

<?php
header('HTTP/1.1 503 Service Temporarily Unavailable',true,503);
?>

Any problems with this? My main concerns are what user's see (which is why i keep static content) and what search engines see (the 503 status code).

Paul Tarjan