Support Center » Knowledgebase » Blocking Countries from accessing your site

Blocking Countries from accessing your site



Before using this function, please contact Quadra Hosting technical support first.

You can block access from certain countries by inserting this in your .htaccess file.

1. Blocking certain countries (all others are allowed)

<IfModule maxminddb_module>
MaxMindDBEnable On
MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code
SetEnvIf MM_COUNTRY_CODE ^(RU|CN) MMCountry
<IfModule authz_core_module>
<RequireAll>
Require all granted
Require not env MMCountry
</RequireAll>
</IfModule>
<IfModule !authz_core_module>
Deny from env=MMCountry
</IfModule>
</IfModule>
In the above example, you are blocking access to your site from Russia and Chinese.

2. Allowing only certain countries (all others are blocked)

<IfModule maxminddb_module>
MaxMindDBEnable On
MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code
SetEnvIf MM_COUNTRY_CODE ^(AU|NZ|US|$) MMCountry
Order Allow,Deny
Allow from env=MMCountry
</IfModule>
In the above example, you are allowing access only from AU (Australia), NZ (New Zealand), and US (USA). In addition, you are also allowing those with IP addresses not in the country database. This will prevent a total ban in the case of a problem with the database itself. 

IMPORTANT: do not block US from accessing your site as this will also block the likes of google and your site will disappear from search results.

For the list of two letter country codes, please see https://en.wikipedia.org/wiki/ISO_3166-1#Current_codes


Article Details
Article ID: 228
Created On: 12 Feb 2016 03:22 PM
 Back
 Login [Lost Password] 
Email:
Password:
Remember Me:
Please note that the login and password to the support area is NOT the same as your hosting control panel login and password
 
 Search
 Article Options
Home | Register | Submit a Ticket | Knowledgebase | Downloads | Control Panel User's Guide | Server Status
Language: