7

I found this web site to generate a .htaccess to block an access from certain country.

The problem with this is that I want to allow access only within Norway. If I use this service, the list will be very long since I have to list all the country IP addresses.

Is there any way to allow access within country, my case is Norway?

shin
  • 31,901
  • 69
  • 184
  • 271
  • 1
    I'm probably wrong (correct me if I am), but wouldn't it work, if you would swap those values from generated .htaccess from order allow,deny to order deny,allow, then replace each deny to allow (to allow all ip's within 1 country) and then, at the end, put deny from all? – Marcin Deptuła Aug 19 '09 at 13:03
  • ad. From gbjbaanb's post I see, that I was very close to the real answer ;). – Marcin Deptuła Aug 19 '09 at 13:04

2 Answers2

5

Change all occurences of 'deny' to allow, and all occurrences of 'allow' to deny. Then move the 'deny from all' condition at the end to the beginning of the list.

eg.

<Limit GET HEAD POST>
order allow,deny
deny from 41.205.32.0/19
deny from .... 
allow from all
</LIMIT>

becomes

<Limit GET HEAD POST>
order deny,allow
deny from all
allow from 41.205.32.0/19
allow from ....
</LIMIT>

There's some good tutorials about .htaccess.

gbjbaanb
  • 51,617
  • 12
  • 104
  • 148
  • do you know how you would do this for just a certain page? – mheavers Mar 31 '11 at 11:54
  • yes. Google says to use the block within the .htaccess file. http://httpd.apache.org/docs/current/mod/core.html#files - note that all .htaccess directives can be put in your httpd.conf instead (and is preferred) – gbjbaanb Apr 01 '11 at 10:56
  • @gbjbaanb this solution is not working for me. Is this no longer valid ? – dark_shadow Dec 04 '16 at 17:01
  • @dark_shadow sorry, been a while.. try the docs from the link I gave in the comment. These things don't tend to change so it should be similar. – gbjbaanb Dec 05 '16 at 12:09
0

There are many geoip database vendors that offer solutions for the problem detailed instructions on the subject. Check out http://www.maxmind.com/app/mod_geoip for an apache module that comes with their database which would probably be a perfect fit for your problem.

code_burgar
  • 12,025
  • 4
  • 35
  • 53