Nginx语法问题'〜*' [英] Nginx syntax problem '~*'

查看:65
本文介绍了Nginx语法问题'〜*'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在检查用户是否有这样的cookie:

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

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

我不熟悉~*语法,我认为那意味着它包含",但是相反呢?例如,如果我想检查$http_cookie是否不包含该Cookie,该怎么办?

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?

推荐答案

您可以使用!~(区分大小写)和!~*(不区分大小写)运算符来测试变量与正则表达式不匹配:

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

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

顺便说一句,如果您要测试一个名为"developer"的cookie值,则可能更清楚地说:

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") {
}

这篇关于Nginx语法问题'〜*'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆