Redirect all visitors except from IP number specified

From time to time it's necessary to block access to people from various parts of the website.  Many people use the following method when developing a site and don't want others to see it. 
You only need to replace the "xxx" with your actual IP number.  You can find your IP number from sites like or any other site.
 RewriteEngine on
 RewriteCond %{REMOTE_ADDR} !^xxx\.xxx\.xxx\.xxx
 RewriteCond %{REQUEST_URI} !/construction.html$ [NC]
 RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css)$ [NC]
 RewriteRule .* /construction.html [R=302,L]
This can also be useful to block areas of your site such as an /admin or /wp-admin section to prevent any outside intrusion attempts.

Reviewed 12/22/2016
  • Email, SSL
  • 26 Users Found This Useful
Was this answer helpful?

Related Articles

How do I redirect a page or folder?

I have removed a file from being on the website and would like to forward people who were looking...

301 Redirect for All Domains

So you've purchased a ton of domains to park on your main account, but you don't want Google to...

301 Redirect from non-www to www -- Without Looping!

So - you want to improve your search engine rankings, and SEO gurus told you that Google might be...

Hotlink protecting image.php and GD images

So you've enabled Cpanel's hotlink protection, but those bandwidth thieves are still attacking...

How to block an IP number

A user is accessing our website and we'd like to block this user as they continue to submit fraud...