I Love the new apache httpd 2.4 with lots of new cool stuff !
我喜欢新的apache httpd 2.4,有很多新的酷东西!
ap_expr is one of these new very promising features,
ap_expr是这些新的非常有前途的功能之一,
..BUT the following SSI snippet don't work as expected:
..但是以下SSI代码段不能按预期工作:
{{if expr="v('HTTP_SESSION') =~ /-user=([^&]+)/"}}
{{set var="user" value="$1"}}
{{endif}}
The if is working BUT the var isn't set ! This doesn't make any sense.
if是工作但是没有设置var!这没有任何意义。
error.log says:
error.log说:
.. AH01330: regex capture $1 is out of range
The doc (http://httpd.apache.org/docs/2.4/expr.html#other) is confusing and have no samples anywhere near.
doc(http://httpd.apache.org/docs/2.4/expr.html#other)令人困惑,并且附近没有样本。
I know that there is a legacy (workaround) switch for SSI.. but I don't want to use it since old Start- and End-tags are forced Legacy
我知道SSI有一个遗留(变通方法)开关..但我不想使用它,因为旧的开始和结束标签是强制遗留的
Doing similar regex-parsing-tricks w SetEnvIfExpr is not helping either
做类似的正则表达式解析 - 技巧SetEnvIfExpr也没有帮助
3 个解决方案
#1
1
by changing
通过改变
{{if expr="v('HTTP_SESSION') =~ /-user=([^&]+)/"}}
{{set var="user" value="$1"}}
{{endif}}
to
至
{{if expr="v('HTTP_SESSION') =~ /-user=([^&]+)/"}}
{{set var="user" value="$0"}}
{{if expr="v('user') =~ /([^&]+)$/"}}
{{set var="user" value="$0"}}
{{endif}}
{{endif}}
one can work around the problem using the fact that $0 seems to work
使用$ 0似乎可行的事实可以解决问题
#2
0
According to the documentation:
根据文件:
Regular expression backreferences The strings $0 ... $9 allow to reference the capture groups from a previously executed, successfully matching regular expressions. They can normally only be used in the same expression as the matching regex, but some modules allow special uses.
正则表达式反向引用字符串$ 0 ... $ 9允许从先前执行的,成功匹配的正则表达式引用捕获组。它们通常只能在与匹配的正则表达式相同的表达式中使用,但某些模块允许特殊用途。
You are using a capturing group and you are referencing that using index 1
, this should be ok using a standard regex engine, but according to the documentation you can reference from $0...$9
. I guess apache is filling the inde 0
with your capturing group instead of 1
and that's you get the regex capture $1 is out of range
您正在使用捕获组,并且您使用索引1引用它,使用标准正则表达式引擎应该没问题,但根据文档,您可以引用$ 0 ... $ 9。我猜apache正在用你的捕获组填充inde 0而不是1,这就是你得到正则表达式捕获$ 1超出范围
Change the index $1
to $0
by using:
使用以下命令将索引$ 1更改为$ 0:
{{if expr="v('HTTP_SESSION') =~ /-user=([^&]+)/"}}
{{set var="user" value="$0"}}
{{endif}}
#3
0
{{if expr="v('HTTP_SESSION') =~ /-user=([^&]+)/ && $1 =~ /(.+)/"}}
{{set var="user" value="$0"}}
{{endif}}
#1
1
by changing
通过改变
{{if expr="v('HTTP_SESSION') =~ /-user=([^&]+)/"}}
{{set var="user" value="$1"}}
{{endif}}
to
至
{{if expr="v('HTTP_SESSION') =~ /-user=([^&]+)/"}}
{{set var="user" value="$0"}}
{{if expr="v('user') =~ /([^&]+)$/"}}
{{set var="user" value="$0"}}
{{endif}}
{{endif}}
one can work around the problem using the fact that $0 seems to work
使用$ 0似乎可行的事实可以解决问题
#2
0
According to the documentation:
根据文件:
Regular expression backreferences The strings $0 ... $9 allow to reference the capture groups from a previously executed, successfully matching regular expressions. They can normally only be used in the same expression as the matching regex, but some modules allow special uses.
正则表达式反向引用字符串$ 0 ... $ 9允许从先前执行的,成功匹配的正则表达式引用捕获组。它们通常只能在与匹配的正则表达式相同的表达式中使用,但某些模块允许特殊用途。
You are using a capturing group and you are referencing that using index 1
, this should be ok using a standard regex engine, but according to the documentation you can reference from $0...$9
. I guess apache is filling the inde 0
with your capturing group instead of 1
and that's you get the regex capture $1 is out of range
您正在使用捕获组,并且您使用索引1引用它,使用标准正则表达式引擎应该没问题,但根据文档,您可以引用$ 0 ... $ 9。我猜apache正在用你的捕获组填充inde 0而不是1,这就是你得到正则表达式捕获$ 1超出范围
Change the index $1
to $0
by using:
使用以下命令将索引$ 1更改为$ 0:
{{if expr="v('HTTP_SESSION') =~ /-user=([^&]+)/"}}
{{set var="user" value="$0"}}
{{endif}}
#3
0
{{if expr="v('HTTP_SESSION') =~ /-user=([^&]+)/ && $1 =~ /(.+)/"}}
{{set var="user" value="$0"}}
{{endif}}