Problem
We need to show the maintenance page to the outside users of our application/website during the deployment of codes or hardware maintenance. We can show the maintenance page or downtime message to the users by making some changes to apache configuration files.
But for internal testing, we need to access the website/application through some internal IP addresses. It can be done easily by adding some Rewrite Conditions (RewriteCond) in apache configuration files /etc/httpd/conf/httpd.conf and /etc/httpd/conf.d/ssl.conf.
Solution
Add the below Rewrite Conditions (RewriteCond) in /etc/httpd/conf/httpd.conf file if your website is running on the http or add same Rewrite Conditions (RewriteCond) in /etc/httpd/conf.d/ssl.conf file if your website is running on https. If some pages of your website running on http and some on https then add these Rewrite Conditions in both the files /etc/httpd/conf/httpd.conf and /etc/httpd/conf.d/ssl.conf.
Add the below Rewrite Conditions (RewriteCond) in /etc/httpd/conf/httpd.conf and /etc/httpd/conf.d/ssl.conf files
RewriteEngine on RewriteCond %{REMOTE_ADDR} !^172\.16\.22\.22$ RewriteCond %{REMOTE_ADDR} !^172\.16\.22\.23$ RewriteRule !dbappweb_maintenance.html /home/docroot/dbappweb_maintenance.html [L]
Restart or Reload the Apache service
[root@dbappweb ~]# service httpd reload Reloading httpd: [ OK ] [root@dbappweb ~]#
OR
[root@dbappweb ~]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ] [root@dbappweb ~]#
Now traffic coming from 172.16.22.22 and 172.16.22.23 will be accepted by the Apache webserver to access the website/application and for other IPs, it will show the maintenance page.
Note: My Apache web server version is 2.2.3 and running on RHEL 5.8.