How to block a continent - but admit one visit from it - SOLVED

I only service people from the Netherlands in Europe. I use GeoIP to block visitors from other continents. Among them North America. I use GeoIP in htaccess to do so.
(GeoIPEnable On
SetEnvIf GEOIP_CONTINENT_CODE NA BlockContinent # Block North America
Deny from env=BlockContinent)

The problem is, that by blocking North America Google ads do not work (google.com).

My question is: can I block North America, but still let Google visit my website?

@denkkracht Hi, here is an example of what you request, many other ways to do it.
Htaccess :

GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
SetEnvIf GEOIP_CONTINENT_CODE NA BlockNA

RewriteEngine On

allow google.com

RewriteCond %{HTTP_HOST} ^(..)?google.com$ [NC]
RewriteRule .
- [L]

block NA except google.gom

RewriteCond %{ENV:BlockNA} ^1$
RewriteRule .* - [F,L]

Sorry for many #### because I can’t quote # in this post (markdown header), really weird.
Anyway, hope that helps. :crossed_fingers:

Hi Bruno,

thanks!

Is it one code for htaccess, or do u present two methods?

  1. GeoIPEnable On

  2. Allow Google … RewriteRule .* - [F,L]

It’s for one htaccess file. Backup yours before starting to play :yum: Check the directory of GeoIP.dat on your server !!!

Htaccess :

GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
SetEnvIf GEOIP_CONTINENT_CODE NA BlockNA

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(..)?google.com$ [NC]
RewriteRule .
- [L]

RewriteCond %{ENV:BlockNA} ^1$
RewriteRule .* - [F,L]

OK.

I just copied the code. So, tomorrow I will know : )

Thanks!

Just be sure that the path to GeoIP.dat is correct on your server. :crossed_fingers:

Before it worked without the link to the database.

Anyway, I just cannot find the .dat-file. I only find mmdb-files on the maxmind-site.

Sorry I didn’t get it already worked. So no problem I think re🤞

The code worked fine, but Google doesnot like it.
I got warnings that Android cannot see the site.

So I deleted it.

Thanx anyway!

@denkkracht Hi, maybe without authorizing the domain but the bot (if you only need it) like this :

<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
SetEnvIf GEOIP_CONTINENT_CODE NA BlockNA
</IfModule>

RewriteEngine On

RewriteCond %{HTTP_USER_AGENT} Googlebot [NC]
RewriteRule .* - [L]

RewriteCond %{ENV:BlockNA} ^1$
RewriteRule .* - [F,L]

Don’t forget to remove the two \ at the line beginnings (markdown format neutralization purpose only :grin:). Last chance if it doesn’t work I have no other option :crossed_fingers::crossed_fingers::crossed_fingers: :shamrock: :four_leaf_clover: