Code Migration – Redirect User to Maintenance Page using .htaccess

One common approach of code migration. Redirect normal users to maintenance page while migration testers carry out production testing after completion. The solution – amend our .htaccess file to redirect all incoming request to maintenance except for request from testers’ office IP address.

#.htaccess
RewriteEngine on

#Check if request is not server_down_message.html and ip is not from testers' ip address
#Change xxx.xxx.xxx.xxx to your ip address, eg. 202.126.4.10
RewriteCond %{REQUEST_URI} !/server_down_message.html$
RewriteCond %{REMOTE_HOST} !^xxx.xxx.xxx.xxx

#To allow more IP addresses, simply append "RewriteCond %{REMOTE_HOST} !^xxx.xxx.xxx.xxx" under this line

#Both conditional are true
#Not requesting for server_down_message.html and IP address not from tester.
#Redirect to server_down_message.html
RewriteRule $ /server_down_message.html [R=302,L]

Hope it helps you and good luck with your migration.