I have two domains www.domain.com and www.domain.com.tw. I want the user to be redirected to the closest server, but if they want to view the other server, they can by clicking a link in the site.
I tried to do it with a cookie, but it doesn't seem to be working. I think the problem is that the cookie is set for the refering URL and not the redirected URL, so nginx doesn't even see the cookie. How can I do this? Here is my attempt so far.
server {
listen 80;
server_name www.domain.com.tw;
set $redir "";
if ($http_accept_language ~* "en") {
set $redir "1";
}
if ($http_cookie ~* "noredir") {
set $redir "";
}
if ($redir = "1") {
rewrite ^ https://www.domain.com/;
}
}