Block a Website for Everyone But You

Avatar of Chris Coyier
Chris Coyier on

Quick little .htaccess trick today for ya’ll. This snippet will redirect any visitor who is not at at one of the provided IP addresses. You can use as many or as few as you would like. This is just a very quick way to block access to a site for, say, everyone but you. Or, everyone but you and a few select co-workers or clients.

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^71\.225\.113\.171
RewriteCond %{REMOTE_HOST} !^71\.185\.239\.212
RewriteCond %{REMOTE_HOST} !^69\.253\.223\.254
RewriteCond %{REQUEST_URI} !/comingsoon\.html$
RewriteRule .* /comingsoon.html [R=302,L]

Thanks for Brian Phillips for sending me this little trick a while back. Definitely useful! An alternative is password protecting the site, which can also be done with .htaccess.