Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewrite rule for "site down" pages

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]
like image 625
Paul Tarjan Avatar asked Aug 26 '09 22:08

Paul Tarjan


3 Answers

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

RewriteCond %{ENV:REDIRECT_STATUS} !=503
RewriteRule ^(.*)$ /503.html [R=503,L]
ErrorDocument 503 /503.html

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

like image 177
Gumbo Avatar answered Oct 27 '22 11:10

Gumbo


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

like image 21
Paul Tarjan Avatar answered Oct 27 '22 10:10

Paul Tarjan


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.

like image 38
Pascal MARTIN Avatar answered Oct 27 '22 11:10

Pascal MARTIN