Country-specific content

Deny or allow access from a specific country

IP address,htaccess

04/02/2011

Recently I was asked to make a site visible to visitors of only a certain country. There's several ways to do this, the easiest being to modify the .htaccess file for your site. I found a site which allows you to generate a list of IP ranges by country. From there, it is a simple matter of modifying or creating an .htaccess file to place in your site's root. To deny access from a certain IP range:



order allow,deny
deny from 41.205.32.0/19
deny from ....
allow from all

and to include from only a certain IP range:



order deny,allow
deny from all
allow from 41.205.32.0/19
allow from ....