.htaccess 测试 ENV 是否为 true 或已定义
如果 ENV 为 true 或已定义(如果未定义,则假定为 false),我需要运行一组 RewriteCond 语句。我一直在尝试使用:
RewriteCond %{ENV:IS_MOBILE} ^true$
RewriteCond ...
和(不确定这是否有效)
RewriteCond %{ENV:IS_MOBILE} !=true
RewriteCond...
但似乎都不起作用。我有什么办法可以做到这一点吗?
I need to run a set of RewriteCond statements if an ENV is true or defined (if not defined, then presumed false). I've been trying to use:
RewriteCond %{ENV:IS_MOBILE} ^true$
RewriteCond ...
and (not sure if this is even valid)
RewriteCond %{ENV:IS_MOBILE} !=true
RewriteCond...
But neither seem to work. Any way I can do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个现实生活中的示例,应该可以帮助您找到解决方案:
如果主机以“s”或“static”开头,则创建一个名为“STATIC”的环境变量并将其设置为“1”:
那么您可能会寻找:如果我的主机是“静态”,那么如果文件被认为是“静态”(img 等),则停止:
现在,如果您想确保该变量不存在,只需检查它是否为空。这是我在上一条之后的规则:它检查变量是否不为空,如果是,则出现错误= 404(模拟“未找到”):
:
在您的情况下,如果您的环境不为空,您认为这是真的 如果您的环境等于您的情况,完全等于字符串
true
,您认为它是“true”:希望这会有所帮助。
Here's a real life sample that should help you to find the solution:
If the host begins by "s" or "static" then create an environment variable called "STATIC" and set it to "1":
Then what you may look for: if my hosts is "static" then if the files are considered "static" (img and so on) then stop:
Now if you want to be sure that the variable doesn't exist, just check if it's empty. Here's my rule just after the previous: it checks if the variable is not empty, and if so, there's an error = 404 (to simulate "not found"):
In your case if your env is not empty you suppose it's true:
In your case if your env is equals, exactly equals to the string
true
you suppose it's "true":Hope this helps.
我认为您需要首先使用
IfDefine
包装代码I think you need to wrap the code using
IfDefine
first