Each site request contains a special header GeoIp-Country-Code
, which contains the visitor's two-letter country code (ISO 3166). The country is determined based on the visitor's IP address as reported by MaxMind GeoLite.
Below are options for solving some typical tasks (in all examples, the specified lines must be added to the beginning of the file .htaccess in site root directory):
Deny access to the site for visitors from China:
RewriteEngine On RewriteCond %{HTTP:GeoIp-Country-Code} ^(CN)$ RewriteRule .* - [F]
Redirect from home page to subsection /ua/
for visitors from Ukraine:
RewriteEngine On RewriteCond %{HTTP:GeoIp-Country-Code} ^(UA)$ RewriteCond %{REQUEST_URI} ^/$ RewriteRule .* /ua/ [L,R=302]
Block POST requests (comments / authorization on the website / posting on the forum) from all countries except Ukraine and Poland:
RewriteEngine On RewriteCond %{HTTP:GeoIp-Country-Code} !^(UA|PL)$ RewriteCond %{REQUEST_METHOD} POST RewriteRule .* - [F]
Block GET requests (page visits / site use) from all countries, except Ukraine and Poland:
RewriteEngine On RewriteCond %{HTTP:GeoIp-Country-Code} !^(UA|PL)$ RewriteCond %{REQUEST_METHOD} GET RewriteRule .* - [F]
from 2-00 to 7-00