O
O
olezhenka2018-04-18 15:29:52
Nginx
olezhenka, 2018-04-18 15:29:52

How to set cookie existence condition on nginx for redirect?

I need the following conditions:
If the user requests the site address "/" and the sid cookie exists, then redirect to "/account/" If the user
requests any other page and the sid cookie does NOT exist, then redirect to "/"
left me:

location ~* ^/$ {
                if ($cookie_sid != "") {
                        rewrite ^(.*)$ /account/ last;
                }
        }

        location / {
                if ($cookie_sid = "") {
                        rewrite ^(.*)$ / break;
                }
                try_files $uri $uri/ /index.html;
                expires 7d;
        }

As a result, when the user goes to "/" and sid is there, he first goes to "/account/" and then immediately to "/".
And when there is no sid, then it's generally an error.
Or maybe try to transfer this processing to nodejs?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2018-04-18
@olezhenka

if doesn't work the way you think
https://www.nginx.com/resources/wiki/start/topics/...
Use map

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question