NGINX: Redirect a user based on cookie for a specific URL only
Let's pretend I've a cookie like so: name=value
server { listen 80; server_name mydomain.com; location ~* ^/$ { if ($cookie_name = "value") { return 301 http://example.com/newsfeed/; } }}
The location block will only match the homepage, check that the cookie exists (you could also just use if ($cookie_name)
), and if present, redirect the user to http://example.com/newsfeed/