如何使用< if> < Elseif> < else>在带有自定义变量的Apache中?
Define FOO "/bar/foo/bar_v1.0.0"
<If "${FOO} == '/bar/foo/bar_v1.0.0'">
Define BAR2 "foofoo1"
</If>
<ElseIf "${FOO} == '/bar/foo/bar_v2.0.0'">
Define BAR2 "foofoo2"
</ElseIf>
<Else>
Define BAR2 "foofoo3"
</Else>
我做错了什么?我已经阅读了 apache docs 和这也是如此,但是我看不到问题。
•我尝试了'$ {foo}'
,$ {foo}
,'%{foo}'
,>%{ foo}
。
•我尝试从字符串中删除引号:&lt;如果“ $ {foo} ==/bar/foo/bar_v1.0.0.0.0“&gt;
•我尝试在全部:&lt;如果$ {foo} =='/bar/foo/bar_v1.0.0.0.0.0'>
•我也尝试了&lt;如果“ $ {foo} =〜/ bar_v1 \ .0 \ .0/“&gt;
and
•&lt;如果“ $ {foo} -strmatch'/bar/foo/bar/bar.v1.0.0.0.0''&gt;
••我还尝试了从定义指令设置的值中删除的报价标记:
define foo/bar/foo/bar_v1.0.0.0
•我尝试删除elsef
block,并仅使用 和else
,并且我总是将bar2定义为“ foofoo3”,因为我将其放入“ else”中的一个例外(默认)值, 万一。因此,无论如何,前两个块永远不会工作。
我不明白,甚至可以在Apache表达式中使用自定义变量吗?该代码位于Apache配置文件中。
我遇到了Apache错误,但没有启动。错误是因为我使用bar2
作为加载模块路径的一部分。当然,Apache说它不能加载模块,因为实际上我没有这样的路径” // usr/usr/foofoo3/some_module”
,但是我当然有” // usr/usr/foofoo1/some_module”
and “/usr/foofoo2/some_module”
,但是正如我所说的那样,前两个块从未工作
Define FOO "/bar/foo/bar_v1.0.0"
<If "${FOO} == '/bar/foo/bar_v1.0.0'">
Define BAR2 "foofoo1"
</If>
<ElseIf "${FOO} == '/bar/foo/bar_v2.0.0'">
Define BAR2 "foofoo2"
</ElseIf>
<Else>
Define BAR2 "foofoo3"
</Else>
What I do wrong? I've read the Apache docs and this one too, but I can't see the problem.
• I've tried '${FOO}'
, ${FOO}
, '%{FOO}'
, %{FOO}
.
• I've tried to remove quotes from the string: <If "${FOO} == /bar/foo/bar_v1.0.0">
• I've tried to remove double quotes at all: <If ${FOO} == '/bar/foo/bar_v1.0.0'>
• I've also tried <If "${FOO} =~ /bar_v1\.0\.0/">
and
• <If "${FOO} -strmatch '/bar/foo/bar.v1.0.0'">
• I've also tried quote marks removed from the values that are set with the Define directive:
Define FOO /bar/foo/bar_v1.0.0
• I've tried to remove ElseIf
block, and use just If
and Else
And I always get BAR2 defined as a "foofoo3", cuz it just an exception (default) value I put in "else", just in case. So first two block never work no matter what.
I don't get it, can I even use custom variables in Apache expressions? The code is located in Apache config file.
I'm getting Apache error and it doesn't start. The error is because I use BAR2
as a part of a path to load module. Of course Apache says it cannot load module, because actually I do not have such path "/usr/foofoo3/some_module"
but I certainly have "/usr/foofoo1/some_module"
and "/usr/foofoo2/some_module"
, but as I said first 2 blocks never work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
昨天我还尝试使用数字而不是字符串进行相同的测试,并产生相同的结果。因此,我感到困惑,失望,实际上已经完成了。我只是用另一种方式弄清楚,在我看来,它并不是那么漂亮,但是我可以处理自己的东西。如果在这里感兴趣的人是代码,它给了我我所需要的:
(我说的完全没有“ foofoo3”,这是一个例外,它是用于测试的,我也以bar2值为“ foofoo3”,在默认部分中测试了该代码))
对此事感到好奇,尤其是@airtower-luna在github上说。因此,我进行了另一个超简单测试:
我做了这么
&lt;如果“ word == word”&gt;
是什么结果?同样的
Yesterday I also tried to do same tests with Numbers instead of String and had the same result. So, I was confused, disappointed and actually done with it. I've just figured out another way, it's not so beautiful in my view, but I work with what I have. If someone interested here's the code, it gives me exactly what I need:
(there's no "foofoo3" at all, as I said it was an exception, it was for testing, and I tested this code with BAR2 value as "foofoo3" too, in DEFAULT section)
Still, I was curious about this matter, especially what @airtower-luna said on github. So I did another super-simple test:
I did this too
<If "word == word">
What is the result? The same ????!!! And I think this is ridiculous! I understand that
config
file it's not a script, but Apache guys madeIfDefine
work at startup, but not a simple-well-known for any coderIf
Else
... I don't know what to say, only - well, ok then (I’m not saying that with meaning/intention to disrespect someone). So, maybe I'll try someday the @mike-kaminski solution, but not today. After all attempts I just really doubt it works at startup at all, as was [said here]