NGINX: Redirect a user based on cookie for a specific URL only NGINX: Redirect a user based on cookie for a specific URL only nginx nginx

NGINX: Redirect a user based on cookie for a specific URL only


Final correct solution:

location ~* ^/$ { if ($http_cookie ~* "wordpress_logged_in") {    return 301 http://example.com/newsfeed/; }}


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/