如何在 Apache 配置中的 If-Else 语句中使用自定义变量?
How do I use a custom variable in an If-Else statement inside an Apache config?
这是我的代码(我已经注释掉了 if-else 部分,因为它不起作用)
snippets/contents 个我的配置文件
/etc/httpd/conf.d/staff.vhost
Define host_domain "staff"
Include /etc/httpd/conf.d/stage_template.vhost
/etc/httpd/conf.d/stage_template.vhost
#<If "${host_domain} == 'main'">
# ServerAlias stage.myhost.com
#</If>
#<Else>
ServerAlias stage-${host_domain}.myhost.com
#</Else>
${host_domain} 可以有 3 个可能的值:主要或员工或客户
我试过:
${host_domain}:我收到这个错误
AH00526:/etc/httpd/conf.d/stage_template.vhost 的第 9 行出现语法错误:无法解析条件子句:语法错误,意外 T_OP_STR_EQ,需要 '('
%{host_domain}:我收到另一个错误
AH00526:/etc/httpd/conf.d/stage_template.vhost 第 9 行的语法错误:
无法解析条件子句:“%”附近的解析错误
谢谢!
编辑:我使用这个 page 作为指南。
<If "false">
...
</If>
看看Expressions in Apache HTTP Server。
编辑:
如果host_domain不是自己创建的变量全部大写${HOST_DOMAIN}
.
并用单引号括起来:
#<If "'${host_domain}' == 'main'">
看看this。
这是我的代码(我已经注释掉了 if-else 部分,因为它不起作用)
snippets/contents 个我的配置文件
/etc/httpd/conf.d/staff.vhost
Define host_domain "staff"
Include /etc/httpd/conf.d/stage_template.vhost
/etc/httpd/conf.d/stage_template.vhost
#<If "${host_domain} == 'main'">
# ServerAlias stage.myhost.com
#</If>
#<Else>
ServerAlias stage-${host_domain}.myhost.com
#</Else>
${host_domain} 可以有 3 个可能的值:主要或员工或客户
我试过:
${host_domain}:我收到这个错误
AH00526:/etc/httpd/conf.d/stage_template.vhost 的第 9 行出现语法错误:无法解析条件子句:语法错误,意外 T_OP_STR_EQ,需要 '('
%{host_domain}:我收到另一个错误
AH00526:/etc/httpd/conf.d/stage_template.vhost 第 9 行的语法错误: 无法解析条件子句:“%”附近的解析错误
谢谢!
编辑:我使用这个 page 作为指南。
<If "false">
...
</If>
看看Expressions in Apache HTTP Server。
编辑:
如果host_domain不是自己创建的变量全部大写${HOST_DOMAIN}
.
并用单引号括起来:
#<If "'${host_domain}' == 'main'">
看看this。