HostGator.com » Support Portal

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

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 http://azuliadesigns.com/block-website-access-country/ 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.

Although it is possible to block an entire region or country using this method, it causes huge amounts of overhead for the Apache web server, due to the large number of htaccess rules that are added. This directly affects performance of your website and the server.

We therefore discourage use of this technique unless there are compelling reasons to do so, and if used, to limit the number of IPs blocked.

For a current list of IP addresses by country, please visit http://www.countryipblocks.net/

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 public_html folder is best, as it can protect all your addon domains and subdomains.

I have a specific IP I want to block.

If you already know the IP address you want to block, click here to read How do I deny access for a specific IP address?


Article Comments

David
Thanks for tip. Blocking countries has reduced my malicious traffic to nearly zero.

HostGator
Thank you for your comments. Just a quick reminder that the comments on this page are not monitored by technical support staff, and that for support issues, it is best to contact us by live chat, phone or email so we can assist you right away.

Although comments are not monitored by technical support staff, they are moderated and read by technical writers. Comments will need to be approved by a moderator before appearing.

Our technical writers do read the comments periodically for the purposes of updating the articles, and do appreciate your feedback, suggestions and corrections to the articles themselves, as well as any suggestions or tips for readers of this article. However, support questions posted here are not guaranteed to be replied to in a timely manner or at all. For support issues, it is best to contact our support staff instead by live chat, email or phone.



Your comments help us keep the knowledge base updated. This is not a medium for support. If you have questions or need help, please contact us via email, phone or live chat for fast assistance.

Post Comment