How to block specific countries from certain pages of my website?

Hi,

I want to know how to block specific countries from certain pages of my website. I want to block 4 countries or so from just my main page and another page. Can this be done cleanly? If so how?

Note: I would like the other pages that I don’t include to work

Much thanks in advance!

Yes. Obtain an ip to location database (free ones are available, with lower accuracy than the paid versions), and use that to identify where the visitor is. You can either put the access logic in the pages (through some server side code which uses the database), or at the web server level (through MaxMind’s mod_geoip for Apache).

Thanks but I don’t have the knowledge to implement that technology, is there an easier way?

That is about as easy as it gets to be able to do that. Of course you also need to keep the list up to date as IPs are occasionally moved between countries. Also there is nothing to prevent someone in a banned country using a proxy server in a country that isn’t banned to be able to bypass the block.

Thanks again, I’ll try to get it to work with help from provider. :slight_smile:

I use htaccess to block out undesirable countries from accessing my website. Before you do something like this though I would consider the undesired impact that this could have for your legit visitors.

Even if your target demographic is local, you might be blocking out some legit visitors who are using AOL as their ISP. AOL uses proxies and someone visiting your website might live in your town, but the IP address they are connecting from could be coming from Europe… or anywhere. Still, there is good reason, in my opinion, to block out certain countries altogether. I know many on here would disagree, but some countries just have too much “bad” traffic to be trusted anymore. Use Google to find out more, I am unable to post links yet!

Hi, if you don’t want to use mod_geoip (and maxmind geo database) this site will generate .htaccess file for you:

http://www.blockacountry.com

In that case you need to block specific countries ip range…You can found out ip’s by using following URL find-ip-address .org/ip-country/

It’d be helpful if there was information, any information, about the source and accuracy of their data. For all I know they randomly generate it.

I think this one is more accurate:

At least IP2Location databases are updated every month.

If you are using WHM/cPanel then it is easy to block entire contry IP ranges from firewall like CSF. For more details how to block entire country in CSF visit following URL:

http://www.vpsdiscussions.com/index.php/topic,87.0.html

I have found that blocking countries is a very effective way to reduce spam as well. It is also a good idea to block the proxies that they use as well.

There are several ways to implement country blocking but it is always a good idea to use a solution that prevents problematic users from coming back.