Use nginx map module: http://nginx.org/en/docs/http/ngx_http_map_module.html#map
The below example will work only when accessing the root location, e.g. http://yoursite/
http {
....
map $geoip_country_code $new_home_uri {
default /en/;
uk /en/;
us /en/;
de /de/;
ru /ru/;
}
....
}
server {
....
location = / {
rewrite ^ $new_home_uri break;
}
location = /de {
# default home for german visitors
...
}
location = /ru {
# default home for russian visitors
...
}
location = /en {
# default home for american, british and any other visitors
...
}
}
The below example will work only when accessing the root location, e.g. http://yoursite/
http {
....
map $geoip_country_code $new_home_uri {
default /en/;
uk /en/;
us /en/;
de /de/;
ru /ru/;
}
....
}
server {
....
location = / {
rewrite ^ $new_home_uri break;
}
location = /de {
# default home for german visitors
...
}
location = /ru {
# default home for russian visitors
...
}
location = /en {
# default home for american, british and any other visitors
...
}
}