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:

While I was looking for that, I found an older one which might also be helpful:

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

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 to help me with this for the sites I own.


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.