There are times when you want to make changes to your website and you do not want your visitors to see the site before you have finished deploying and testing the website. Here is an example using Apache, mod_rewrite and a cookie set by a PHP page.
First, create your maintenance webpage called maintenance.html. Second, create a file called set_cookie.php with the following contents
<?php
setcookie(“testing”, “testing”, time()+36000); /* expire in 600 minutes */
?>
Next, create a file called .htaccess in your main web directory with the following contents
RewriteEngine on
RewriteCond %{HTTP_COOKIE} !testing
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteCond %{REQUEST_URI} !/set_cookie.php$
RewriteCond %{REQUEST_URI} !/logo\.jpg$
RewriteRule ^(.*) /maintenance.html [NC,L]
Lastly, in your web browser, go to http://www.yourdomain.com/set_cookie.php. From that point on, you will be able to browse your website, but your visitors will be redirected to your maintenance.html webpage
