Nginx syntax problem '~*'

2019-06-01 00:00发布

I have at condition checking to see if user has a cookie like this:

 if ($http_cookie ~* "developer=true" ) {
   ...
 }

I'm not familiar with the ~* syntax, I assume that that means if it 'contains', but what about the opposite? like what if I wanted to check if $http_cookie doesn't contain that cookie?

标签: nginx
1条回答
做自己的国王
2楼-- · 2019-06-01 00:36

You can test the variable does not match a regex using !~ (case sensitive) and !~* (case-insensitive) operators:

if ($http_cookie !~* "developer=true") {
}

By the way, if you want to test a value of cookie named "developer", it would be probably more clear to say:

if ($cookie_developer = "true") {
}
查看更多
登录 后发表回答