Return to Snippet

Revision: 44974
at July 30, 2012 22:31 by macodev


Updated Code
I recently needed to move one website from a shared web host to our internal server. After some discussion, we decided to simply add a "Site Down For Maintenance" page to the site to prevent users from submitting orders during the hosting change. Using the following .htaccess code snippet, we were able to send all users to a maintenance.html page no matter which page they requested:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^maintenance\.html$
RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]

***

Once we posted the maintenance.html page and .htaccess code on both the old hosting environment AND new hosting environment, we switched the DNS settings. Before making the switch, we had ported the website's code to a "utility" domain and made adjustments so that the website would function well in the new hosting environment. Now that the DNS had been changed, we wanted to make sure that the website would function well on the new domain within the new hosting environment. Unfortunately the code above blocks EVERYONE from accessing any file besides the maintenance.html file. Fortunately my gifted IT team had the answer:

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^11\.111\.111\.111
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]

Revision: 44973
at April 21, 2011 17:26 by macodev


Initial Code
I recently needed to move one website from a shared web host to our internal server. After some discussion, we decided to simply add a "Site Down For Maintenance" page to the site to prevent users from submitting orders during the hosting change. Using the following .htaccess code snippet, we were able to send all users to a maintenance.html page no matter which page they requested:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]

***

Once we posted the maintenance.html page and .htaccess code on both the old hosting environment AND new hosting environment, we switched the DNS settings. Before making the switch, we had ported the website's code to a "utility" domain and made adjustments so that the website would function well in the new hosting environment. Now that the DNS had been changed, we wanted to make sure that the website would function well on the new domain within the new hosting environment. Unfortunately the code above blocks EVERYONE from accessing any file besides the maintenance.html file. Fortunately my gifted IT team had the answer:

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^11\.111\.111\.111
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]

Initial URL
http://davidwalsh.name/htaccess-maintenance-page-redirect

Initial Description
Site Down For Maintenance

Initial Title
.htaccess Site Down For Maintenance

Initial Tags
htaccess

Initial Language
Apache