Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache regex backreferences UNREACHABLE in httpd 2.4?

I Love the new apache httpd 2.4 with lots of new cool stuff !

ap_expr is one of these new very promising features,

..BUT the following SSI snippet don't work as expected:

{{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.

error.log says:

.. 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.

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

Doing similar regex-parsing-tricks w SetEnvIfExpr is not helping either

like image 716
kjetildm Avatar asked Apr 18 '13 19:04

kjetildm


1 Answers

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

like image 200
lijat Avatar answered Nov 08 '22 11:11

lijat