Redirecting Visitors to a Holding Page while you Develop a New Site (Apache)
When you are uploading and testing a new site on the same domain as an existing site you need to keep the public from seeing a part finished site while you are uploading the files and sorting out any problems.
The best way to do this for those of us using Apache, is to create a holding page and redirect traffic from IP addresses other than your own while you are uploading and debugging.
This can be done using a .htaccess file.
1. Create a directory in your document root directory named “maintenance”
2. Upload your holding page and all linked files (index.htm, images, css etc) here
3. Add the following to your .htaccess file to the domain root
## MAINTENANCE MESSAGE WITH DEVELOPER ACCESS ##
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !127\.0\.0\.1
RewriteRule !^maintenance/ http://www.yourdomain.com/maintenance/ [R,L]
Just change the 127\.0\.0\.1 for your own IP keeping the slashes in place. If you want you can add more IPs to grant access to the client or other developers.
## MAINTENANCE MESSAGE WITH DEVELOPER ACCESS ##
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !127\.0\.0\.1 [OR]
RewriteCond %{REMOTE_ADDR} !127\.0\.0\.2 [OR]
RewriteCond %{REMOTE_ADDR} !127\.0\.0\.3
RewriteRule !^maintenance/ http://www.yourdomain.com/maintenance/ [R,L]
The message is temporary and is therefore we use a 302 redirect.
This article was posted on 21 May 2010 in Apache, Code
That's the end of this article. I hope you found it useful. If you're enjoyed this article why don't you have a look around the archives, where you can find some more tutorials, tips and general ramblings.