Nginx geoip redirect based on country codes but exclude googlebot

Hello,

I want to redirect people to specific pages on a website according to
their country but i dont want to redirect googlebot or other spiders,
how can i do this with nginx ?

I have done redirection with php earlier but havent been able to exclude
googlebot.

As i read from maxmind website, on apache its done like this

GeoIPEnable On
GeoIPDBFile /path/to/GeoIP.dat

# Redirect one country
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteRule ^(.*)$ http://www.canada.com$1 [L]

# Redirect multiple countries to a single page
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(CA|US|MX)$
RewriteRule ^(.*)$ http://www.northamerica.com$1 [L]

It still does not have any info to remove googlebot from redirection.

Thanks for any help.

Posted at Nginx Forum:

Am 17.11.2010 um 13:55 schrieb st1905:

As i read from maxmind website, on apache its done like this

Redirect multiple countries to a single page

RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(CA|US|MX)$
RewriteRule ^(.*)$ http://www.northamerica.com$1 [L]
[/code]

It still does not have any info to remove googlebot from redirection.

We did it like this (not for google - you have to find their ip-space)

http {
keepalive_timeout 65;
geoip_country /usr/local/etc/geo/GeoIP.dat ;

these are the GeoIP exceptions for your site

 geo $mygeo {
             default         0;
             bla/19  1;
             blu/16    1;
 }

then, in the server block:

     location / {
         include proxy-lcb-lt.conf;
         if ($geoip_country_code = "US") {
                             proxy_pass http://prod;
             }
         # these are the exceptions, defined in nginx.conf:
         if ($mygeo = "1") {
             proxy_pass http://prod;
             }
     }

Hope this helps.

Rainer

Hello,

Thank you for the reply, i`m going to try using this on my
configuration, i was thinking to exclude it by referrer which googlebot
uses but maybe using ip would work too, in fact the ips would change.

Posted at Nginx Forum:

Hello,

Posted at Nginx Forum:
Re: Nginx geoip redirect based on country codes but exclude googlebot

The GoogleBot header can be faked.See e.g.
http://www.zhacks.com/2010/05/06/view-restricted-website-by-cloacking-as-googlebot/
I’d go for the IP range.
Hendrik

Hello,

Just to confirm, your configuration works fine, i have applied it today,
still wondering if it would be better to use refferrer or ip ? Any
suggestions ? Thank you.

Posted at Nginx Forum:

Thank you for that information. Using ip now.

Posted at Nginx Forum: