In the testing phase in some projects I want to have maintenance time during some hours each day. Of course I can tell the testpersons that the site will be unavailable during certain hours, and I do, but the human memory too often fails to remember such important pieces of information. Instead of just relying on the human frailty I made some rewriting rules to make it obvious for those who have not been gifted. This is the solution I came up with.
The site normally redirects all traffic from port 80 to port 443, ie from ordinary web traffic to encrypted traffic. But during 8.00 to 10.00 users are redirected to a special maintenance page unless the user making the request is one of the developers sitting on a certain subnet. That means that the developers can go berserk on the web pages during the given time slot. But at 10 o'clock the site has to be functional again.
The rewrite rule for the ordinary web (port 80) site looks like this:
# Redirect users during maintenance hours
# ===========================================
RewriteEngine on
# If the request comes in between 8-10 a clock
RewriteCond %{TIME_HOUR}%{TIME_MIN} >759
RewriteCond %{TIME_HOUR}%{TIME_MIN} <1000
# and the source of the request is not from subnet 102,103
RewriteCond %{REMOTE_ADDR} !^192\.168\.10[2|3]\.[0-9]{1,3}$
# But allow to fetch objects that are part of the maintenance page
RewriteCond %{REQUEST_URI} !^\/maintenance\.html [NC]
RewriteCond %{REQUEST_URI} !^\/stylesheets\/.*$ [NC]
RewriteCond %{REQUEST_URI} !^\/images\/.*$ [NC]
RewriteCond %{REQUEST_URI} !^\/favicon.ico [NC]
RewriteRule ^(.*)$ http://%{SERVER_NAME}/maintenance.html [R=302,NC,L]
# All other hours redirect to SSL encrypted site
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^/(.*)$ https://%{SERVER_NAME}/$1 [L,R]
On the SSL site all direct requests to the site have to be handled equally - all requests are redirected to maintenance page during 8.00 until 10.00
# Redirect users during maintenance hours
# ===========================================
RewriteEngine on
# If the request comes in between 8-10 a clock
RewriteCond %{TIME_HOUR}%{TIME_MIN} >0759
RewriteCond %{TIME_HOUR}%{TIME_MIN} <1000
# and the source of the request is not from subnet 102,103
RewriteCond %{REMOTE_ADDR} !^192\.168\.10[2|3]\.[0-9]{1,3}$
RewriteRule ^(.*)$ http://%{SERVER_NAME}/maintenance.html [R=302,NC,L]
That's it!
Comments
Post new comment