Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache 2.4.3 SSI if expr no variables?

Tags:

apache

ssi

I have many files with small differences. The included file contains this, which tries to differentiate on one part of a longer path:

<!--#if expr="${DOCUMENT_URI}=/internet/"-->Internet<!--#else-->Intranet<!--#endif-->

In the error log I get

AH01337: Could not parse expr "${DOCUMENT_URI}=/internet/" in /opt/apache/htdocs/ssi/time.shtml: Parse error near '$'

I find many variations on this theme, like no braces, parentheses around the inside of the quotes, space before the comment end or =~, but nothing helps. There doesn't seem to be a debug setting for mod_include, which would tell me what's wrong...

Another variant I found is

<!--#if expr='"${DOCUMENT_URI}"=~/internet/'-->

this gives no error. But it always chooses the else branch, likewise with REQUEST_URI, as though the variables were unset. But I can echo them fine. I also tried /.+internet.+/ in case it was anchoring this.

Since these are CGI variables I also tried loading cgid_module – no good either.

like image 619
Daniel Avatar asked Jan 28 '13 18:01

Daniel


2 Answers

As of version 2.3.13, mod_include has switched to the new ap_expr syntax for conditional expressions in #if flow control elements.

Add the SSILegacyExprParser on directive to switch to the old syntax which is compatible with Apache HTTPD version 2.2.x and earlier.

http://httpd.apache.org/docs/current/mod/mod_include.html#ssilegacyexprparser

like image 107
Tom Curran Avatar answered Oct 04 '22 15:10

Tom Curran


As many other people noted you can use the v("foo") style, but the examples given in the Apache 2.4 documentation (http://httpd.apache.org/docs/2.4/expr.html#examples) give this form:

<!--#if expr="%{DOCUMENT_URI} =~ /internet/"-->Internet<!--#else-->Intranet<!--#endif-->

Note the % instead of $ on the variable, and the =~ for regex match.

I've just tested this and it works fine.

(Or use SSILegacyExprParser on as also mentioned, to allow for backward-compatibility with the 2.2.x format. But I expect this compatibility will be removed at some point in the distant future..)

like image 40
David Gardner Avatar answered Oct 04 '22 15:10

David Gardner