Deny Access to All IPs Except Yours .htaccess Solution

By | May 1, 2008

Sometimes you need to perform any specific tasks that require nobody accesses the page while it is being edited. There may be some tests, database update or anything else. So your task is to deny access to your site from all ips except yours. Note, that all your site visitors should not be redirected anywhere, but should be shown a message that your site will be available soon, or something in this way. You need to allow access from your IP only and others should be redirected to a specific page of your site. I am going to show you 2 .htaccess solutions:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^site.ru
RewriteCond %{REMOTE_ADDR} !^111.111.111.111
RewriteRule ^(.*)$ http://site.com/under_construction.html [L]

The second one is to use 403 page of your site:
Order deny,allow
Allow from 127.0.0.1 111.111.111.111
Deny from all

ErrorDocument 403 /reconstruction.html

You need to replace 111.111.111.111 with your IP and everything should be solved!