Apache allows you to include only select portions of a server document using conditional statements. These conditional statements are based on the value of server-side variables initialized earlier using the SSI set command. The Apache flow-control statements allow you to effectively customize a document without adding more complex CGI programs to perform the same task.
There are four Apache flow-control statements:
<!--#if expr="expression" --> <!--#elif expr="expression"--> <!--#else--> <!--#endif-->
Each works as you would expect from an ordinary scripting language. Note that each if must have a closing endif server-side statement. For example:
<!--#if expr="$myvar=activated" --> <B>The variable appears to be activated</B> <!--#elif expr="$myvar=inactive"--> <B>The variable appears to be inactive</B> <!--#else--> <B>The variable has an unknown value</B> <!--#endif-->
Table 13-2 shows the allowed expressions, where the order of operations is as expected in a traditional programming language. Note that in some cases, var2 is allowed to be an egrep-based regular expression if it is surrounded by slashes (/) on both sides.
Expression |
Meaning |
---|---|
var |
True if the variable is not empty |
var1=var2 |
True if the variables match |
var1!=var2 |
True if the variables do not match |
var1<var2 |
True if the first variable is less than the second |
var1<=var2 |
True if the first variable is less than or equal to the second |
var1>var2 |
True if the first variable is greater than the second |
var1>=var2 |
True if the first variable is greater than or equal to the second |
(expr) |
True if the enclosed condition is true |
!expr |
True if the condition is false |
expr1&&expr2 |
True if both expressions evaluate to true |
expr1||expr2 |
True if either expressions evaluates to true |
Finally, you can place regular strings inside single quotes to preserve any whitespaces. If a string is not quoted, extra whitespaces are ignored. For example:
this is too much space
This string does not have quotes and will be collapsed to:
this is too much space
However, if you place the string in single quotes, the whitespace is preserved:
/'this is too much space/'
You can also place strings in double quotes, but you will have to escape each one while inside the expr="" expression, as shown here:
<!--#if expr="\" $HTTP_REFERER\" != " -->
Copyright © 2003 O'Reilly & Associates. All rights reserved.