Block countries from website

I would like to block a few countries from my website, I have been told that htaccess is the way to do it. Can anybody tell me how to do this and if I need to contact my host about doing it.
Thank you

It’s not easy to block a whole nation, because each nation has a large range of IP addresses. Still, there are sites that keep records of these. Have a look at ip2nation.

There was another thread on a similar subject recently: http://www.sitepoint.com/forums/showthread.php?815637-How-to-Block-my-Website-in-China

While I was looking for that, I found an older one which might also be helpful:http://www.sitepoint.com/forums/showthread.php?652613-How-to-block-specific-countries-from-certain-pages-of-my-website

Than you for that I will read the whole thread and it might clear things up for me.
Thanks again
Sandra

I contacted my web host and asked if there was anything in the current htaccess file I needed to keep and they fixed my problem for me. They have allowed only the countries I deal with access to my site, which is perfect.
Thank you for your suggestions and thank you Digital Pacific for your great support.

Cool, glad you found a solution. I didn’t know hosts offered that service. Funnily enough, I just moved to the same host recently, so good to know. :slight_smile:

I dont know if you need another opinion as it seems your problem is solved but there are some tools that help you with controlling the visitors of your sites. You can choose which countries will have access to your website. I found the Traffic Gatekeeper of Rankvision.com to help me with this for the sites I own.

alex,

They’re using JavaScript to block countries. IMHO, it’s better to use the PHP script that Ralph and TechnoBear suggested as it’s far more reliable (and, I believe, faster). OR you could download the country IP list and keep that in your own db (MUCH faster) so a quick check of your own db would be all that’s required to select country codes and either block of allow.

Regards,

DK