Allow only US users to visit site

.htaccess, apache

Solution

You have to install `mod_geoip`

On Debian:

apt-get install libapache2-mod-geoip

edit /etc/apache2/mods-available/geoip.conf
<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
</IfModule>

/etc/init.d/apache2 reload

Then you can limit access to visitors except from US with the following lines:

 SetEnvIf GEOIP_COUNTRY_CODE US AllowedCountry

 Deny from all
 Allow from env=AllowedCountry

Problem

What is the best .htaccess configuration to allow only US users to visit a site? I can't seem to find a definitive answer that covers all IPV4 and IPV6 users.

Original source