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?
Bruno
May 31, 2024, 10:05am
2
@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
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.
Hi Bruno,
thanks!
Is it one code for htaccess, or do u present two methods?
GeoIPEnable On
Allow Google … RewriteRule .* - [F,L]
Bruno
May 31, 2024, 10:36am
4
It’s for one htaccess file. Backup yours before starting to play 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!
Bruno
May 31, 2024, 11:11am
6
Just be sure that the path to GeoIP.dat is correct on your server.
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.
Bruno
May 31, 2024, 12:22pm
8
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!
Bruno
June 3, 2024, 7:56am
10
@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 ). Last chance if it doesn’t work I have no other option