Key-Six
Key-Six

Reputation: 2469

Block certain country using .htaccess

Is there a simple and reliable way to block certain countries using .htaccess?

Simple means no IP range block lists - they need to be updated once in a while and can be quite long.

I understand, that it wouldn't apply to proxies.

Upvotes: 1

Views: 2523

Answers (1)

Jon Lin
Jon Lin

Reputation: 143886

Easiest is probably using the GeoIP Apache module. After installing and configuring you just need to do something like this in your htaccess file:

GeoIPEnable On
GeoIPDBFile /path/to/GeoIP.dat

SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry
# ... place more countries here

Deny from env=BlockCountry

Upvotes: 2

Related Questions