Showing a temporary page for all visitors but yourself

By Leon Dijk. Filed under Tutorials & Snippets. 0 comments.

Whenever I'm creating a new site on a public domain or when I have to upgrade or drastically change a live website, I usually put up a "Coming soon" or "Maintenance" page for all visitors but me.

Here's the code I use in my .htaccess in order to accomplish just that. In this case I've created a temporary page with all images for the design of the page in a "comingsoon" directory in the root of my website.

# Show temporary page for everyone but certain IP addresses.

# My home IP:
RewriteCond %{REMOTE_HOST} !^123\.123\.123\.1

# My work IP:
RewriteCond %{REMOTE_HOST} !^123\.123\.123\.2

# Server IP (needed in some cases):
RewriteCond %{REMOTE_HOST} !^123\.123\.123\.3

# Don't redirect requests for files that are needed for the temporary page:
RewriteCond %{REQUEST_URI} !/comingsoon/index\.html$
RewriteCond %{REQUEST_URI} !/comingsoon/logo\.gif$
RewriteCond %{REQUEST_URI} !/comingsoon/favicon\.ico$

# Redirect all other requests to the temporary page:
RewriteRule .* /comingsoon/index.html [R=302,L]

Add those lines somewhere at the top of your .htaccess file in the root of your website and that should be it!
I usually visit the site with my mobile phone to see if it works correctly.

As with all .htaccess modifications, be careful. It could break your site. The code above works for me, but might not work for you due to different server settings. If it doesn't work, you'll probably get a Internal Server Error (500) message.

Be the first to submit a comment!

Submit your comment

Sorry, comments are closed for this page.