Can I block an IP or an entire region or country from seeing my site?

Can I block an IP or an entire region or country from seeing my site?

Wed 03 October 12 Comments are Closed

Yes, you can block visitors per their IP address. Countries will have a specific IP address range, and you can use that information to block all or some of their IP’s.  There are more than one way to do this:

Blocking a Country or Region using PHP

Searching the internet, we found a unique solution for blocking countries and regions via IP addresses with some PHP coding.

Visit for more details about this method, including example code.

Blocking a Country or Region with htaccess Deny Rules

Another way to do it is to block IP ranges in the .htaccess file for your site.

For a current list of IP addresses by country, please visit

On the resulting page, click the “.htaccess deny” link for the desired country. This is the exact code you should paste in your .htaccess file.

Usually the .htaccess in your webpage/ folder is best, as it can protect all your addon domains and subdomains.

I have a specific IP I want to block.

To block multiple IP addresses, list them one per line by editing your .htaccess file, for example:

order allow,deny
deny from
deny from
deny from
allow from all

You can also block an entire IP block/range. Here we will not specify the last octet in the .htaccess file.

deny from 127.0.0

This will refuse access for any user with an address in the to range.

Instead of using numeric addresses, domain names (and subdomain names) can be used to ban users.

deny from

It bans users with a remote hostname ending in This would stop all users connected to the internet via from viewing your site.

If you only want to allow certain IPs to connect to your website, you can set an option for deny from all, which will deny everyone.

This must be done by coding your .htaccess file as follows:

deny from all
allow from
allow from #my house

Using .htaccess to block an entire range or name is likely to lock out innocent users. Use with caution.

Rate This Entry:
1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)
  • There are no tags for this post

back to top