SSI on Apache 2.4+, Conditional Statements – new format

I moved my site to a new server, and all of my conditional SSI statements stopped working. There is plenty of documentation for using SSILegacyExprParser, but very little documentation on the new method.

I used SSI to deliver a different html file depending on the domain visited. Originally, this was to get past my web host restrictions for total domains. However, when a particular client has many domains with very simple websites, I prefer to have all files in the same folder.

After the update, I was getting the following errors in my error.log folder:
[Tue Feb 17 01:58:08.865059 2015] [include:error] [pid 4855] [client]: Could not parse expr "$HTTP_HOST = """ in /var/www/ Parse error near '$'
[Tue Feb 17 01:52:11.580714 2015] [include:error] [pid 4294] [client]: Could not parse expr "%{HTTP_HOST}" in /var/www/ syntax error, unexpected T_OP_CONCAT, expecting '('

This is a result of the new syntax requirements for conditional expressions in Apache 2.4 and newer. Here is the code that worked for me:

<!--#if expr='%{HTTP_HOST} = "" || %{HTTP_HOST} = ""' -->
<!--#include virtual="page1.html" -->
<!--#elif expr='%{HTTP_HOST} = "" || %{HTTP_HOST} = ""' -->
<!--#include virtual="page2.html" -->
<!--#elif expr='%{HTTP_HOST} = "" || %{HTTP_HOST} = ""' -->
<!--#include virtual="page3.html" -->
<!--#include virtual="others.html" -->

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Please enter 10 numbers for Captcha: * Time limit is exhausted. Please reload the CAPTCHA.