Question

NGINX GeoIP Redirect and Search Engine Bots

Posted June 10, 2020 173 views
NginxWordPress

I have managed to get NGINX GEOIP by Country to redirect, the following is what I have done:

nginx.conf

http {

        ##
        # Add GeoIP to NGINX
        ##
        geoip_city /usr/share/GeoIP/GeoLiteCity.dat;
        geoip_country /usr/share/GeoIP/GeoIP.dat;
...
}

in my host file I placed the following

map $geoip_city_country_code $closest_server {
    default example.com;
    NZ      nz.example.com;
    CA      ca.example.com;
    US      us.example.com;
    GB      gb.example.com;
}

server {
...
server_name example.com nz.example.com ca.example.com us.example.com gb.example.com;
...
if ($closest_server != $host) {
    rewrite ^ $scheme://$closest_server$request_uri break;
}

What I need it to do is to redirect to the closest server but also allow the user to select another international subdomain and not redirect.

Secondly, I need to exclude search engine bots to be excluded from these rules.

Any assistance would be great.

edited by KFSys
Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!