How to block a whole country from visiting your website
Sun Jul 10, 2011 9:30 pm
How to block a whole country from visiting your website
There are times when you may want to ban visitors from a certain country from viewing your website, the reasons for this can be many.
You can block people from viewing your website using rules in your firewall IP tables but if you dont have access to that, you can edit the .htaccess file and add a list of IPs to be blocked, you can get the whole IP range from a country from countryipblocks.
Select one or more country you want to block on home page of www.countryipblocks.net and press Choose Countries
Now on next screen you can see set of command, copy it and paste it to your .htaccess file, in case if you don’t have it in ftp then kindly talk to your host or create one using notepad or another text editor. This code having set of IP from countries you selected and it simply reject visitors request from those countries.
Upload that .htaccess file into root of your domain using a ftp client. Every time when a visitor request your site from server it look into .htaccess file and if IP address of that visitor fall with in range of all denied IPs of your .htaccess then it will simply deny visitor request.
However this solution may cause server overload if many requests are made from that country, another easier way to do this, is by banning people from accessing your website according to their browser language set up, for example to ban people who is using a Chinese internet browser you will add to your .htaccess file:
RewriteCond %{HTTP_ACCEPT_LANGUAGE} zh-CN
RewriteRule .* – [F]
THis will generate error 403 message, and the visitor will get a “Forbidden” message when visiting your page, but it can be changed to something else. The zh-CN is the browser setting for Chinese, this can be changed to any other language you like.
There are times when you may want to ban visitors from a certain country from viewing your website, the reasons for this can be many.
You can block people from viewing your website using rules in your firewall IP tables but if you dont have access to that, you can edit the .htaccess file and add a list of IPs to be blocked, you can get the whole IP range from a country from countryipblocks.
Select one or more country you want to block on home page of www.countryipblocks.net and press Choose Countries
Now on next screen you can see set of command, copy it and paste it to your .htaccess file, in case if you don’t have it in ftp then kindly talk to your host or create one using notepad or another text editor. This code having set of IP from countries you selected and it simply reject visitors request from those countries.
Upload that .htaccess file into root of your domain using a ftp client. Every time when a visitor request your site from server it look into .htaccess file and if IP address of that visitor fall with in range of all denied IPs of your .htaccess then it will simply deny visitor request.
However this solution may cause server overload if many requests are made from that country, another easier way to do this, is by banning people from accessing your website according to their browser language set up, for example to ban people who is using a Chinese internet browser you will add to your .htaccess file:
RewriteCond %{HTTP_ACCEPT_LANGUAGE} zh-CN
RewriteRule .* – [F]
THis will generate error 403 message, and the visitor will get a “Forbidden” message when visiting your page, but it can be changed to something else. The zh-CN is the browser setting for Chinese, this can be changed to any other language you like.
Permissions in this forum:
You cannot reply to topics in this forum
|
|