Block Region or Country from Viewing Your Site
Posted by ASO Admin on 07 February 2020 01:33 PM
|
|
Methods for Denying Access to Specific Regions or CountriesThere are three methods by which you can prevent visitors from a specific location from visiting your website: custom rules in CloudFlare, Apache Deny Rules, using a combo of CloudFlare and .htaccess Rules. Custom Rules in CloudFlareFor this method to work, a CloudFlare account is required and it must be enabled for the domain you want to block traffic for. See here for more info about CloudFlare.
This will add a new rule to your Block List which will deny visitors matching the rules you selected from reaching your domain. It will also prevent your cPanel from being accessed via the domain by blocked locations (in addition to the website itself). The Apache Deny DirectiveThe Apache Deny directive allows you to block visitors from accessing your Linux server from a given IP address. Using this method in .htaccess will give you direct control over access to your server and can block unwanted visitors. Incorrectly used, however, it can have negative effects on your traffic and site performance. Blocking a Country or Region with .htaccess Deny RulesAlthough it is possible to block an entire region or country using this method, we very strongly recommend against it. Using deny directives will cause Apache to check the entire list for matches on every single request, of which there may be dozens per single page load. This directly affects performance of your website and the server as a whole and may drastically slow things down. Therefore, we discourage use of this technique unless there are compelling reasons to do so. If used, we ask that you strictly limit the number of IPs blocked. Using a Combination of CloudFlare and .htaccess RulesFor this method to work, a CloudFlare account is required and it must be enabled for the domain you want to block traffic for. See here for more info about CloudFlare. SetEnvIf CF-IPCountry IN BuzzOff=1 By editing this code to adding a line for any country you wish to block, and using the correct country code, you can effectively restrict access to different parts of your site or the site as a whole. A complete list of country codes may be found here. Blocking Specific IPsIf you already know a specific IP address you want to block, you can use the IP Deny Manager in cPanel to do so. How to find out a visitor's IP addressUse the web statistics tools to find more information on your visitors. We suggest you go to cPanel and click the Latest Visitors icon. Look for the Host information; it could be an IP or a domain name. How to block the IP address
How to unblock the IP address
Deny AllYou can also set an option for 'deny from all', which will deny everyone. This must be done by coding your .htaccess file as follows:
Note: it is possible to block access to yourself accidentally by using this method. Be sure to allow access via your IP otherwise you will be blocked as well. You can find out your current IP address by visiting the Find Your IP Address page. If you accidentally block yourself, please contact us. You will need to confirm your identity before we can unblock your IP. | |
|