How to block a specific IP Address from accessing your Website

If you have annoying visitors, site scrapers, or spammers, you may find it useful to block these users from accessing your website content. You can block bad visitors by IP Address (or blocks of IP Addresses) using a .htaccess file. Below are some useful examples.

In the following example, all IP Addresses and domains are accepted, except for xxx.xxx.xxx.xxx and bad-site-example.com.

# allow all except those indicated here
<Files *>
order allow,deny
allow from all
deny from xxx.xxx.xxx.xxx
deny from .*bad-site-example\.com.*
</Files> 

In the following example, all IP addresses are denied access except for xxx.xxx.xxx.xxx and good-site-example.com.

# Deny access to everyone, except those listed here:
<Files *>
order deny,allow
deny from all
allow from xxx.xxx.xxx.xxx
allow from .*good-site-example\.com.*
</Files> 

Trackback URI | Comments RSS

Leave a Reply

You must be logged in to post a comment.