Difference between revisions of "How to block or allow countries using GeoIP and .htaccess"
From Brian Nelson Ramblings
(Created page with "==How to block or allow countries using GeoIP and .htaccess== First you will want to to install GeoIP and mod_geoip ===Block Countries u...") |
(→Block Countries using GeoIP and .htaccess) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 12: | Line 12: | ||
SetEnvIf GEOIP_COUNTRY_CODE KR DenyCountry | SetEnvIf GEOIP_COUNTRY_CODE KR DenyCountry | ||
SetEnvIf GEOIP_COUNTRY_CODE KP DenyCountry | SetEnvIf GEOIP_COUNTRY_CODE KP DenyCountry | ||
+ | SetEnvIf GEOIP_COUNTRY_CODE <Country Code> DenyCountry | ||
Allow from all | Allow from all | ||
− | Deny from env=DenyCountry | + | Deny from env=DenyCountry |
===Allow Countries using GeoIP and .htaccess=== | ===Allow Countries using GeoIP and .htaccess=== | ||
Line 28: | Line 29: | ||
Deny from all | Deny from all | ||
Allow from env=AllowCountry | Allow from env=AllowCountry | ||
+ | |||
+ | ===Redirect to Specific page based on Country=== | ||
+ | |||
+ | The following will redirect United States and Canada traffic to the /USA folder | ||
+ | |||
+ | RewriteEngine on | ||
+ | RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(US|CA)$ | ||
+ | RewriteRule ^(.*)$ http://www.mydomain.com/USA/$1 [L] | ||
====List of Country Code from Maxmind==== | ====List of Country Code from Maxmind==== | ||
http://dev.maxmind.com/geoip/legacy/codes/iso3166/ | http://dev.maxmind.com/geoip/legacy/codes/iso3166/ |
Latest revision as of 14:39, 22 March 2018
Contents
How to block or allow countries using GeoIP and .htaccess
First you will want to to install GeoIP and mod_geoip
Block Countries using GeoIP and .htaccess
The following will deny from China, North Korea, South Korea
GeoIPEnable On # Put countries to deny here SetEnvIf GEOIP_COUNTRY_CODE CN DenyCountry SetEnvIf GEOIP_COUNTRY_CODE KR DenyCountry SetEnvIf GEOIP_COUNTRY_CODE KP DenyCountry SetEnvIf GEOIP_COUNTRY_CODE <Country Code> DenyCountry Allow from all Deny from env=DenyCountry
Allow Countries using GeoIP and .htaccess
The following will allow only from US, Canada and Mexico
GeoIPEnable On # Put countries to allow here SetEnvIf GEOIP_COUNTRY_CODE US AllowCountry SetEnvIf GEOIP_COUNTRY_CODE CA AllowCountry SetEnvIf GEOIP_COUNTRY_CODE MX AllowCountry Deny from all Allow from env=AllowCountry
Redirect to Specific page based on Country
The following will redirect United States and Canada traffic to the /USA folder
RewriteEngine on RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(US|CA)$ RewriteRule ^(.*)$ http://www.mydomain.com/USA/$1 [L]