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]
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With