dwkd
dwkd

Reputation: 2896

Allow only US users to visit site

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.

Upvotes: 3

Views: 1222

Answers (2)

Pekka
Pekka

Reputation: 3654

You don't indicate a reason for the restriction, but in general, there is no way to limit users geographically. Consider as two obvious counter examples, a user connected through a corporate VPN browsing through a US-hosted proxy server, or a US mobile phone being used to access the web while roaming abroad - not to even mention anonymising networks like Tor.

Even worse, unless you specifically disallow Google-like search engine access, readers can view the cached copies of the page contents.

Upvotes: 1

Adam
Adam

Reputation: 18807

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

Upvotes: 7

Related Questions