O
O
olezhenka2018-04-20 14:59:41
Nginx
olezhenka, 2018-04-20 14:59:41

Why is the regex not working correctly?

I need to condition that the sid cookie does not exist. I checked in the logs, when the cookie does not exist, then "-" is put instead of it.
So I wrote the following:

map $cookie_sid:$request_uri $redirect_uri {
                "~^-:/[\d\w/]+$"                "/";
        }

If the cookie does not exist and the request goes to a directory further than /, for example: /account, /search, etc., then set the $redirect_uri variable to "/";
Nothing works as I described, the logs show the following:
$cookie_sid:$request_uri => -:/account
But $redirect_uri is not defined, it is empty.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2018-04-20
@olezhenka

map $cookie_sid:$request_uri $redirect_uri {
    "~^:/[\d\w/]+$" "/";
}

A non-existent cookie is an empty string. The hyphen ( - ) in the logs is just a logging feature.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question