2

let's say I have a website (www.abc.com/featured/abc) and wanted to redirecting (only that link) the viewer from other country except Malaysia to youtube video.. But www.abc.com is still worldwide. And yes, my server is already compiling with geoip module.

here is what i did in etc/nginx/sites-available/abc.com

location featured/abc/ {
  if ($geoip_country_code != "MY") {
    rewrite ^ https://www.youtube.com/watch?v=MaMuQPmzrrU;
  }
}

but it still not working. Do I did somewhere wrong in the code

Amirol Ahmad
  • 532
  • 5
  • 21

1 Answers1

3

Try map variable like this:

http {
...
map $geoip_country_code $georedirect {
  default 0;
  MY 1;
}
...
}

server {
...
location /featured/abc/ {
  if ($georedirect) {
    return 301 https://www.youtube.com/watch?v=MaMuQPmzrrU;
  }
}
...
}

More info: Module ngx_http_map_module

Aleksey Deryagin
  • 2,575
  • 2
  • 20
  • 18