如何使用< if> < Elseif> < else>在带有自定义变量的Apache中?

发布于 2025-01-30 12:35:08 字数 1552 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫竹語嫣☆ 2025-02-06 12:35:08

昨天我还尝试使用数字而不是字符串进行相同的测试,并产生相同的结果。因此,我感到困惑,失望,实际上已经完成了。我只是用另一种方式弄清楚,在我看来,它并不是那么漂亮,但是我可以处理自己的东西。如果在这里感兴趣的人是代码,它给了我我所需要的:
(我说的完全没有“ foofoo3”,这是一个例外,它是用于测试的,我也以bar2值为“ foofoo3”,在默认部分中测试了该代码)

Define BAR__v1_0_0 "OK"

# CONDITIONAL
<IfDefine BAR__v1_0_0 >
    Define FOO "/bar/foo/bar_v1.0.0"
    Define BAR2 "foofoo1"
</IfDefine>
<IfDefine BAR__v2_0_0 >
    Define FOO "/bar/foo/bar_v2.0.0"
    Define BAR2 "foofoo2"
</IfDefine>

# DEFAULT
<IfDefine !FOO>
    Define FOO "/bar/foo/bar_v1.0.0"
    Define BAR2 "foofoo1"
</IfDefine>

对此事感到好奇,尤其是@airtower-luna在github上说。因此,我进行了另一个超简单测试:

<If "'word' == 'word'">
    Define BAR2 "foofoo1"
</If>
<ElseIf "'noword' == 'word'">
    Define BAR2 "foofoo2"
</ElseIf>
<Else>
    Define BAR2 "foofoo3"
</Else>

我做了这么&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)

Define BAR__v1_0_0 "OK"

# CONDITIONAL
<IfDefine BAR__v1_0_0 >
    Define FOO "/bar/foo/bar_v1.0.0"
    Define BAR2 "foofoo1"
</IfDefine>
<IfDefine BAR__v2_0_0 >
    Define FOO "/bar/foo/bar_v2.0.0"
    Define BAR2 "foofoo2"
</IfDefine>

# DEFAULT
<IfDefine !FOO>
    Define FOO "/bar/foo/bar_v1.0.0"
    Define BAR2 "foofoo1"
</IfDefine>

Still, I was curious about this matter, especially what @airtower-luna said on github. So I did another super-simple test:

<If "'word' == 'word'">
    Define BAR2 "foofoo1"
</If>
<ElseIf "'noword' == 'word'">
    Define BAR2 "foofoo2"
</ElseIf>
<Else>
    Define BAR2 "foofoo3"
</Else>

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 made IfDefine work at startup, but not a simple-well-known for any coder If 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]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文