2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
7 Licensed to the Apache Software Foundation (ASF) under one or more
8 contributor license agreements. See the NOTICE file distributed with
9 this work for additional information regarding copyright ownership.
10 The ASF licenses this file to You under the Apache License, Version 2.0
11 (the "License"); you may not use this file except in compliance with
12 the License. You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
23 <modulesynopsis metafile="mod_include.xml.meta">
25 <name>mod_include</name>
26 <description>Server-parsed html documents (Server Side Includes)</description>
28 <sourcefile>mod_include.c</sourcefile>
29 <identifier>include_module</identifier>
32 <p>This module provides a filter which will process files
33 before they are sent to the client. The processing is
34 controlled by specially formatted SGML comments, referred to as
35 <dfn>elements</dfn>. These elements allow conditional text, the
36 inclusion of other files or programs, as well as the setting and
37 printing of environment variables.</p>
39 <seealso><directive module="core">Options</directive></seealso>
40 <seealso><directive module="core">AcceptPathInfo</directive></seealso>
41 <seealso><a href="../filter.html">Filters</a></seealso>
42 <seealso><a href="../howto/ssi.html">SSI Tutorial</a></seealso>
44 <section id="enabling">
45 <title>Enabling Server-Side Includes</title>
47 <p>Server Side Includes are implemented by the
48 <code>INCLUDES</code> <a href="../filter.html">filter</a>. If
49 documents containing server-side include directives are given
50 the extension .shtml, the following directives will make Apache
51 parse them and assign the resulting document the mime type of
52 <code>text/html</code>:</p>
54 <highlight language="config">
55 AddType text/html .shtml
56 AddOutputFilter INCLUDES .shtml
59 <p>The following directive must be given for the directories
60 containing the shtml files (typically in a
61 <directive module="core" type="section">Directory</directive> section,
62 but this directive is also valid in <code>.htaccess</code> files if
63 <directive module="core">AllowOverride</directive> <code>Options</code>
66 <highlight language="config">
70 <p>For backwards compatibility, the <code>server-parsed</code>
71 <a href="../handler.html">handler</a> also activates the
72 INCLUDES filter. As well, Apache will activate the INCLUDES
73 filter for any document with mime type
74 <code>text/x-server-parsed-html</code> or
75 <code>text/x-server-parsed-html3</code> (and the resulting
76 output will have the mime type <code>text/html</code>).</p>
78 <p>For more information, see our <a
79 href="../howto/ssi.html">Tutorial on Server Side Includes</a>.</p>
80 </section> <!-- /enabling -->
82 <section id="pathinfo">
83 <title>PATH_INFO with Server Side Includes</title>
85 <p>Files processed for server-side includes no longer accept
86 requests with <code>PATH_INFO</code> (trailing pathname information)
87 by default. You can use the <directive
88 module="core">AcceptPathInfo</directive> directive to
89 configure the server to accept requests with <code>PATH_INFO</code>.</p>
90 </section> <!-- /pathinfo -->
92 <section id="elements"><title>Available Elements</title>
93 <p>The document is parsed as an HTML document, with special
94 commands embedded as SGML comments. A command has the syntax: </p>
97 <!--#<var>element</var> <var>attribute</var>=<var>value</var>
98 <var>attribute</var>=<var>value</var> ... -->
101 <p>The value will often be enclosed in double quotes, but single
102 quotes (<code>'</code>) and backticks (<code>`</code>) are also
103 possible. Many commands only allow a single attribute-value pair.
104 Note that the comment terminator (<code>--></code>) should be
105 preceded by whitespace to ensure that it isn't considered part of
106 an SSI token. Note that the leading <code><!--#</code> is <em>one</em>
107 token and may not contain any whitespaces.</p>
109 <p>The allowed elements are listed in the following table:</p>
112 <tr><th>Element</th><th>Description</th></tr>
113 <tr><td><code><a href="#element.config">config</a></code></td>
114 <td>configure output formats</td></tr>
115 <tr><td><code><a href="#element.echo">echo</a></code></td>
116 <td>print variables</td></tr>
117 <tr><td><code><a href="#element.exec">exec</a></code></td>
118 <td>execute external programs</td></tr>
119 <tr><td><code><a href="#element.fsize">fsize</a></code></td>
120 <td>print size of a file</td></tr>
121 <tr><td><code><a href="#element.flastmod">flastmod</a></code></td>
122 <td>print last modification time of a file</td></tr>
123 <tr><td><code><a href="#element.include">include</a></code></td>
124 <td>include a file</td></tr>
125 <tr><td><code><a href="#element.printenv">printenv</a></code></td>
126 <td>print all available variables</td></tr>
127 <tr><td><code><a href="#element.set">set</a></code></td>
128 <td>set a value of a variable</td></tr>
131 <p>SSI elements may be defined by modules other than
132 <module>mod_include</module>. In fact, the <code><a
133 href="#element.exec">exec</a></code> element is provided by
134 <module>mod_cgi</module>, and will only be available if this
135 module is loaded.</p>
137 <section id="element.config"><title>The config Element</title>
138 <p>This command controls various aspects of the parsing. The
139 valid attributes are:</p>
142 <dt><code>echomsg</code> (<em>Apache 2.1 and later</em>)</dt>
143 <dd><p>The value is a message that is sent back to the
144 client if the <code><a href="#element.echo">echo</a></code> element
145 attempts to echo an undefined variable. This overrides any <directive
146 module="mod_include">SSIUndefinedEcho</directive> directives.</p>
149 <!--#config echomsg="[Value Undefined]" -->
153 <dt><code>errmsg</code></dt>
154 <dd><p>The value is a message that is sent back to the
155 client if an error occurs while parsing the
156 document. This overrides any <directive
157 module="mod_include">SSIErrorMsg</directive> directives.</p>
160 <!--#config errmsg="[Oops, something broke.]" -->
164 <dt><code>sizefmt</code></dt>
165 <dd><p>The value sets the format to be used when displaying
166 the size of a file. Valid values are <code>bytes</code>
167 for a count in bytes, or <code>abbrev</code> for a count
168 in Kb or Mb as appropriate, for example a size of 1024 bytes
169 will be printed as "1K".</p>
172 <!--#config sizefmt="abbrev" -->
177 <dt><code>timefmt</code></dt>
178 <dd><p>The value is a string to be used by the
179 <code>strftime(3)</code> library routine when printing
183 <!--#config timefmt=""%R, %B %d, %Y"" -->
188 </section> <!-- /config -->
190 <section id="element.echo"><title>The echo Element</title>
191 <p>This command prints one of the <a href="#includevars">include
192 variables</a> defined below. If the variable is unset, the result is
193 determined by the <directive module="mod_include"
194 >SSIUndefinedEcho</directive> directive. Any dates printed are
195 subject to the currently configured <code>timefmt</code>.</p>
200 <dt><code>var</code></dt>
201 <dd>The value is the name of the variable to print.</dd>
203 <dt><code>decoding</code></dt>
204 <dd><p>Specifies whether Apache should strip an encoding from
205 the variable before processing the variable further. The default
206 is <code>none</code>, where no decoding will be done. If set to
207 <code>url</code>, then URL decoding (also known as %-encoding;
208 this is appropriate for use within URLs in links, etc.) will be
209 performed. If set to <code>urlencoded</code>,
210 application/x-www-form-urlencoded compatible encoding (found in
211 query strings) will be stripped. If set to <code>base64</code>,
212 base64 will be decoded, and if set to <code>entity</code>, HTML
213 entity encoding will be stripped. Decoding is done prior to any
214 further encoding on the variable. Multiple encodings can be
215 stripped by specifying more than one comma separated encoding.
216 The decoding setting will remain in effect until the next decoding
217 attribute is encountered, or the element ends.</p>
219 <p>The <code>decoding</code> attribute must <em>precede</em> the
220 corresponding <code>var</code> attribute to be effective.</p>
223 <dt><code>encoding</code></dt>
224 <dd><p>Specifies how Apache should encode special characters
225 contained in the variable before outputting them. If set
226 to <code>none</code>, no encoding will be done. If set to
227 <code>url</code>, then URL encoding (also known as %-encoding;
228 this is appropriate for use within URLs in links, etc.) will be
229 performed. If set to <code>urlencoded</code>,
230 application/x-www-form-urlencoded compatible encoding will be
231 performed instead, and should be used with query strings. If set
232 to <code>base64</code>, base64 encoding will be performed. At
233 the start of an <code>echo</code> element, the default is set to
234 <code>entity</code>, resulting in entity encoding (which is
235 appropriate in the context of a block-level HTML element,
236 <em>e.g.</em> a paragraph of text). This can be changed by adding
237 an <code>encoding</code> attribute, which will remain in effect
238 until the next <code>encoding</code> attribute is encountered or
239 the element ends, whichever comes first.</p>
241 <p>The <code>encoding</code> attribute must <em>precede</em> the
242 corresponding <code>var</code> attribute to be effective.</p>
244 <note type="warning">
245 In order to avoid cross-site scripting issues, you should
246 <em>always</em> encode user supplied data.
249 <example><title>Example</title>
250 <!--#echo encoding="entity" var="QUERY_STRING" -->
254 </section> <!-- /echo -->
256 <section id="element.exec"><title>The exec Element</title>
257 <p>The <code>exec</code> command executes a given shell command or
258 CGI script. It requires <module>mod_cgi</module> to be present
259 in the server. If <directive module="core">Options</directive>
260 <code>IncludesNOEXEC</code> is set, this command is completely
261 disabled. The valid attributes are:</p>
264 <dt><code>cgi</code></dt>
265 <dd><p>The value specifies a (%-encoded) URL-path to
266 the CGI script. If the path does not begin with a slash (/),
267 then it is taken to be relative to the current
268 document. The document referenced by this path is
269 invoked as a CGI script, even if the server would not
270 normally recognize it as such. However, the directory
271 containing the script must be enabled for CGI scripts
272 (with <directive module="mod_alias">ScriptAlias</directive>
273 or <directive module="core">Options</directive>
274 <code>ExecCGI</code>).</p>
276 <p>The CGI script is given the <code>PATH_INFO</code> and query
277 string (<code>QUERY_STRING</code>) of the original request from the
278 client; these <em>cannot</em> be specified in the URL path. The
279 include variables will be available to the script in addition to
280 the standard <a href="mod_cgi.html">CGI</a> environment.</p>
282 <example><title>Example</title>
283 <!--#exec cgi="/cgi-bin/example.cgi" -->
286 <p>If the script returns a <code>Location:</code> header instead of
287 output, then this will be translated into an HTML anchor.</p>
289 <p>The <code><a href="#includevirtual">include virtual</a></code>
290 element should be used in preference to <code>exec cgi</code>. In
291 particular, if you need to pass additional arguments to a CGI program,
292 using the query string, this cannot be done with <code>exec
293 cgi</code>, but can be done with <code>include virtual</code>, as
297 <!--#include virtual="/cgi-bin/example.cgi?argument=value" -->
301 <dt><code>cmd</code></dt>
302 <dd><p>The server will execute the given string using
303 <code>/bin/sh</code>. The <a href="#includevars"
304 >include variables</a> are available to the command, in addition
305 to the usual set of CGI variables.</p>
307 <p>The use of <code><a href="#includevirtual"
308 >#include virtual</a></code> is almost always prefered to using
309 either <code>#exec cgi</code> or <code>#exec cmd</code>. The former
310 (<code>#include virtual</code>) uses the standard Apache sub-request
311 mechanism to include files or scripts. It is much better tested and
314 <p>In addition, on some platforms, like Win32, and on unix when
315 using <a href="../suexec.html">suexec</a>, you cannot pass arguments
316 to a command in an <code>exec</code> directive, or otherwise include
317 spaces in the command. Thus, while the following will work under a
318 non-suexec configuration on unix, it will not produce the desired
319 result under Win32, or when running suexec:</p>
322 <!--#exec cmd="perl /path/to/perlscript arg1 arg2" -->
326 </section> <!-- /exec -->
328 <section id="element.fsize"><title>The fsize Element</title>
329 <p>This command prints the size of the specified file, subject
330 to the <code>sizefmt</code> format specification. Attributes:</p>
333 <dt><code>file</code></dt>
334 <dd>The value is a path relative to the directory
335 containing the current document being parsed.
338 This file is <!--#fsize file="mod_include.html" --> bytes.
341 The value of <code>file</code> cannot start with a slash
342 (<code>/</code>), nor can it contain <code>../</code> so as to
343 refer to a file above the current directory or outside of the
344 document root. Attempting to so will result in the error message:
345 <code>The given path was above the root path</code>.
348 <dt><code>virtual</code></dt>
349 <dd>The value is a (%-encoded) URL-path. If it does not begin with
350 a slash (/) then it is taken to be relative to the current document.
351 Note, that this does <em>not</em> print the size of any CGI output,
352 but the size of the CGI script itself.</dd>
356 This file is <!--#fsize virtual="/docs/mod/mod_include.html" --> bytes.
359 <p>Note that in many cases these two are exactly the same thing.
360 However, the <code>file</code> attribute doesn't respect URL-space
362 </section> <!-- /fsize -->
364 <section id="element.flastmod"><title>The flastmod Element</title>
365 <p>This command prints the last modification date of the
366 specified file, subject to the <code>timefmt</code> format
367 specification. The attributes are the same as for the
368 <code><a href="#element.fsize">fsize</a></code> command.</p>
369 </section> <!-- /flastmod -->
371 <section id="element.include"><title>The include Element</title>
372 <p>This command inserts the text of another document or file
373 into the parsed file. Any included file is subject to the usual
374 access control. If the directory containing the parsed file has
375 <a href="core.html#options">Options</a>
376 <code>IncludesNOEXEC</code> set, then only documents with a text
377 <glossary>MIME-type</glossary> (<code>text/plain</code>,
378 <code>text/html</code> etc.) will be included. Otherwise CGI
379 scripts are invoked as normal using the complete URL given in
380 the command, including any query string.</p>
382 <p>An attribute defines the location of the document, and may
383 appear more than once in an include element; an inclusion is
384 done for each attribute given to the include command in turn.
385 The valid attributes are:</p>
388 <dt><code>file</code></dt>
389 <dd>The value is a path relative to the directory
390 containing the current document being parsed. It cannot
391 contain <code>../</code>, nor can it be an absolute path.
392 Therefore, you cannot include files that are outside of the
393 document root, or above the current document in the directory
394 structure. The <code>virtual</code> attribute should always be
395 used in preference to this one.</dd>
397 <dt><code><a id="includevirtual" name="includevirtual"
398 >virtual</a></code></dt>
399 <dd><p>The value is a (%-encoded) URL-path. The URL cannot contain a
400 scheme or hostname, only a path and an optional query string. If it
401 does not begin with a slash (/) then it is taken to be relative to the
402 current document.</p>
404 <p>A URL is constructed from the attribute, and the output the
405 server would return if the URL were accessed by the client is
406 included in the parsed output. Thus included files can be nested.</p>
408 <p>If the specified URL is a CGI program, the program will be
409 executed and its output inserted in place of the directive in the
410 parsed file. You may include a query string in a CGI url:</p>
413 <!--#include virtual="/cgi-bin/example.cgi?argument=value" -->
416 <p><code>include virtual</code> should be used in preference
417 to <code>exec cgi</code> to include the output of CGI programs
418 into an HTML document.</p>
420 <p>If the <directive module="mod_request">KeptBodySize</directive>
421 directive is correctly configured and valid for this included
422 file, attempts to POST requests to the enclosing HTML document
423 will be passed through to subrequests as POST requests as well.
424 Without the directive, all subrequests are processed as GET
429 <dt><code>onerror</code></dt>
430 <dd><p>The value is a (%-encoded) URL-path which is shown should a
431 previous attempt to include a file or virtual attribute failed.
432 To be effective, this attribute must be specified after the
433 file or virtual attributes being covered. If the attempt to
434 include the onerror path fails, or if onerror is not specified, the
435 default error message will be included.</p>
438 # Simple example<br />
439 <!--#include virtual="/not-exist.html" onerror="/error.html" -->
443 # Dedicated onerror paths<br />
444 <!--#include virtual="/path-a.html" onerror="/error-a.html" virtual="/path-b.html" onerror="/error-b.html" -->
449 </section> <!-- /include -->
451 <section id="element.printenv"><title>The printenv Element</title>
452 <p>This prints out a plain text listing of all existing variables and
453 their values. Special characters are entity encoded (see the <code><a
454 href="#element.echo">echo</a></code> element for details)
455 before being output. There are no attributes.</p>
457 <example><title>Example</title>
459 <!--#printenv -->
462 </section> <!-- /printenv -->
464 <section id="element.set"><title>The set Element</title>
465 <p>This sets the value of a variable. Attributes:</p>
468 <dt><code>var</code></dt>
469 <dd>The name of the variable to set.</dd>
471 <dt><code>value</code></dt>
472 <dd>The value to give a variable.</dd>
474 <dt><code>decoding</code></dt>
475 <dd><p>Specifies whether Apache should strip an encoding from
476 the variable before processing the variable further. The default
477 is <code>none</code>, where no decoding will be done. If set to
478 <code>url</code>, <code>urlencoded</code>, <code>base64</code>
479 or <code>entity</code>, URL decoding,
480 application/x-www-form-urlencoded decoding, base64 decoding or HTML
481 entity decoding will be performed respectively. More than one
482 decoding can be specified by separating with commas. The decoding
483 setting will remain in effect until the next decoding attribute
484 is encountered, or the element ends. The <code>decoding</code>
485 attribute must <em>precede</em> the corresponding
486 <code>var</code> attribute to be effective.</p>
489 <dt><code>encoding</code></dt>
490 <dd><p>Specifies how Apache should encode special characters
491 contained in the variable before setting them. The default is
492 <code>none</code>, where no encoding will be done. If set to
493 <code>url</code>, <code>urlencoding</code>, <code>base64</code>
494 or <code>entity</code>, URL encoding,
495 application/x-www-form-urlencoded encoding, base64 encoding or
496 HTML entity encoding will be performed respectively. More than
497 one encoding can be specified by separating with commas. The
498 encoding setting will remain in effect until the next encoding
499 attribute is encountered, or the element ends. The
500 <code>encoding</code> attribute must <em>precede</em> the
501 corresponding <code>var</code> attribute to be effective.
502 Encodings are applied after all decodings have been
507 <example><title>Example</title>
508 <!--#set var="category" value="help" -->
510 </section> <!-- /set -->
511 </section> <!-- /basic elements -->
513 <section id="includevars">
514 <title>Include Variables</title>
516 <p>In addition to the variables in the standard CGI environment,
517 these are available for the <code>echo</code> command, for
518 <code>if</code> and <code>elif</code>, and to any program
519 invoked by the document.</p>
522 <dt><code>DATE_GMT</code></dt>
523 <dd>The current date in Greenwich Mean Time.</dd>
525 <dt><code>DATE_LOCAL</code></dt>
526 <dd>The current date in the local time zone.</dd>
528 <dt><code>DOCUMENT_NAME</code></dt>
529 <dd>The filename (excluding directories) of the document
530 requested by the user.</dd>
532 <dt><code>DOCUMENT_URI</code></dt>
533 <dd>The (%-decoded) URL path of the document requested by the
534 user. Note that in the case of nested include files, this is
535 <em>not</em> the URL for the current document. Note also that
536 if the URL is modified internally (e.g. by an <directive
537 module="mod_alias">alias</directive> or <directive
538 module="mod_dir">directoryindex</directive>), the modified
541 <dt><code>LAST_MODIFIED</code></dt>
542 <dd>The last modification date of the document requested by
545 <dt><code>QUERY_STRING_UNESCAPED</code></dt>
546 <dd>If a query string is present, this variable contains the
547 (%-decoded) query string, which is <em>escaped</em> for shell
548 usage (special characters like <code>&</code> etc. are
549 preceded by backslashes).</dd>
553 <section id="substitution"><title>Variable Substitution</title>
555 <p>Variable substitution is done within quoted strings in most
556 cases where they may reasonably occur as an argument to an SSI
557 directive. This includes the <code>config</code>,
558 <code>exec</code>, <code>flastmod</code>, <code>fsize</code>,
559 <code>include</code>, <code>echo</code>, and <code>set</code>
560 directives. If <directive module="mod_include"
561 >SSILegacyExprParser</directive> is set to <code>on</code>,
562 substitution also occurs in the arguments to conditional operators.
563 You can insert a literal dollar sign into the string using backslash
567 <!--#set var="cur" value="\$test" -->
570 <p>If a variable reference needs to be substituted in the
571 middle of a character sequence that might otherwise be
572 considered a valid identifier in its own right, it can be
573 disambiguated by enclosing the reference in braces,
574 <em>a la</em> shell substitution:</p>
577 <!--#set var="Zed" value="${REMOTE_HOST}_${REQUEST_METHOD}" -->
580 <p>This will result in the <code>Zed</code> variable being set
581 to "<code>X_Y</code>" if <code>REMOTE_HOST</code> is
582 "<code>X</code>" and <code>REQUEST_METHOD</code> is
583 "<code>Y</code>".</p>
586 <section id="flowctrl">
587 <title>Flow Control Elements</title>
589 <p>The basic flow control elements are:</p>
592 <!--#if expr="<var>test_condition</var>" --><br />
593 <!--#elif expr="<var>test_condition</var>" --><br />
594 <!--#else --><br />
598 <p>The <code>if</code> element works like an if statement in a
599 programming language. The test condition is evaluated and if
600 the result is true, then the text until the next <code>elif</code>,
601 <code>else</code> or <code>endif</code> element is included in the
604 <p>The <code>elif</code> or <code>else</code> statements are used
605 to put text into the output stream if the original
606 <var>test_condition</var> was false. These elements are optional.</p>
608 <p>The <code>endif</code> element ends the <code>if</code> element
611 <p><var>test_condition</var> is a boolean expression which follows the
612 <a href="../expr.html">ap_expr</a> syntax. The syntax can be changed
613 to be compatible with Apache HTTPD 2.2.x using <directive
614 module="mod_include">SSILegacyExprParser</directive>.</p>
616 <p>The SSI variables set with the <code>var</code> element are exported
617 into the request environment and can be accessed with the
618 <code>reqenv</code> function. As a short-cut, the function name
619 <code>v</code> is also available inside <module>mod_include</module>.</p>
621 <p>The below example will print "from local net" if client IP address
622 belongs to the 10.0.0.0/8 subnet.</p>
625 <!--#if expr='-R "10.0.0.0/8"' --><br />
629 <!--#else --><br />
631 from somewhere else<br />
636 <p>The below example will print "foo is bar" if the variable
637 <code>foo</code> is set to the value "bar".</p>
640 <!--#if expr='v("foo") = "bar"' --><br />
647 <note><title>Reference Documentation</title>
648 <p>See also: <a href="../expr.html">Expressions in Apache HTTP Server</a>,
649 for a complete reference and examples. The <em>restricted</em> functions
650 are not available inside <module>mod_include</module></p>
654 <section id="legacyexpr">
655 <title>Legacy expression syntax</title>
657 <p>This section describes the syntax of the <code>#if expr</code>
658 element if <directive module="mod_include">SSILegacyExprParser</directive>
659 is set to <code>on</code>.</p>
662 <dt><code><var>string</var></code></dt>
663 <dd>true if <var>string</var> is not empty</dd>
665 <dt><code><var>-A string</var></code></dt>
666 <dd><p>true if the URL represented by the string is accessible by
667 configuration, false otherwise. This is useful where content on a
668 page is to be hidden from users who are not authorized to view the
669 URL, such as a link to that URL. Note that the URL is only tested
670 for whether access would be granted, not whether the URL exists.</p>
672 <example><title>Example</title>
673 <!--#if expr="-A /private" --><br />
675 Click <a href="/private">here</a> to access private
682 <dt><code><var>string1</var> = <var>string2</var><br />
683 <var>string1</var> == <var>string2</var><br />
684 <var>string1</var> != <var>string2</var></code></dt>
686 <dd><p>Compare <var>string1</var> with <var>string2</var>. If
687 <var>string2</var> has the form <code>/<var>string2</var>/</code>
688 then it is treated as a regular expression. Regular expressions are
689 implemented by the <a href="http://www.pcre.org">PCRE</a> engine and
690 have the same syntax as those in <a href="http://www.perl.com">perl
691 5</a>. Note that <code>==</code> is just an alias for <code>=</code>
692 and behaves exactly the same way.</p>
694 <p>If you are matching positive (<code>=</code> or <code>==</code>), you
695 can capture grouped parts of the regular expression. The captured parts
696 are stored in the special variables <code>$1</code> ..
697 <code>$9</code>. The whole string matched by the regular expression is
698 stored in the special variable <code>$0</code></p>
700 <example><title>Example</title>
701 <!--#if expr="$QUERY_STRING = /^sid=([a-zA-Z0-9]+)/" --><br />
703 <!--#set var="session" value="$1" --><br />
709 <dt><code><var>string1</var> < <var>string2</var><br />
710 <var>string1</var> <= <var>string2</var><br />
711 <var>string1</var> > <var>string2</var><br />
712 <var>string1</var> >= <var>string2</var></code></dt>
714 <dd>Compare <var>string1</var> with <var>string2</var>. Note, that
715 strings are compared <em>literally</em> (using
716 <code>strcmp(3)</code>). Therefore the string "100" is less than
719 <dt><code>( <var>test_condition</var> )</code></dt>
720 <dd>true if <var>test_condition</var> is true</dd>
722 <dt><code>! <var>test_condition</var></code></dt>
723 <dd>true if <var>test_condition</var> is false</dd>
725 <dt><code><var>test_condition1</var> &&
726 <var>test_condition2</var></code></dt>
727 <dd>true if both <var>test_condition1</var> and
728 <var>test_condition2</var> are true</dd>
730 <dt><code><var>test_condition1</var> ||
731 <var>test_condition2</var></code></dt>
732 <dd>true if either <var>test_condition1</var> or
733 <var>test_condition2</var> is true</dd>
736 <p>"<code>=</code>" and "<code>!=</code>" bind more tightly than
737 "<code>&&</code>" and "<code>||</code>". "<code>!</code>" binds
738 most tightly. Thus, the following are equivalent:</p>
741 <!--#if expr="$a = test1 && $b = test2" --><br />
742 <!--#if expr="($a = test1) && ($b = test2)" -->
745 <p>The boolean operators <code>&&</code> and <code>||</code>
746 share the same priority. So if you want to bind such an operator more
747 tightly, you should use parentheses.</p>
749 <p>Anything that's not recognized as a variable or an operator
750 is treated as a string. Strings can also be quoted:
751 <code>'string'</code>. Unquoted strings can't contain whitespace
752 (blanks and tabs) because it is used to separate tokens such as
753 variables. If multiple strings are found in a row, they are
754 concatenated using blanks. So,</p>
757 <p><code><var>string1</var> <var
758 >string2</var></code> results in <code><var>string1</var> <var
759 >string2</var></code><br />
763 <code>'<var>string1</var> <var
764 >string2</var>'</code> results in <code><var
765 >string1</var> <var>string2</var></code>.</p>
768 <note><title>Optimization of Boolean Expressions</title>
769 <p>If the expressions become more complex and slow down processing
770 significantly, you can try to optimize them according to the
771 evaluation rules:</p>
773 <li>Expressions are evaluated from left to right</li>
774 <li>Binary boolean operators (<code>&&</code> and <code>||</code>)
775 are short circuited wherever possible. In conclusion with the rule
776 above that means, <module>mod_include</module> evaluates at first
777 the left expression. If the left result is sufficient to determine
778 the end result, processing stops here. Otherwise it evaluates the
779 right side and computes the end result from both left and right
781 <li>Short circuit evaluation is turned off as long as there are regular
782 expressions to deal with. These must be evaluated to fill in the
783 backreference variables (<code>$1</code> .. <code>$9</code>).</li>
785 <p>If you want to look how a particular expression is handled, you can
786 recompile <module>mod_include</module> using the
787 <code>-DDEBUG_INCLUDE</code> compiler option. This inserts for every
788 parsed expression tokenizer information, the parse tree and how it is
789 evaluated into the output sent to the client.</p>
792 <note><title>Escaping slashes in regex strings</title>
793 <p>All slashes which are not intended to act as delimiters in your regex must
794 be escaped. This is regardless of their meaning to the regex engine.</p>
800 <name>SSIEndTag</name>
801 <description>String that ends an include element</description>
802 <syntax>SSIEndTag <var>tag</var></syntax>
803 <default>SSIEndTag "-->"</default>
804 <contextlist><context>server config</context><context>virtual host</context>
808 <p>This directive changes the string that <module>mod_include</module>
809 looks for to mark the end of an include element.</p>
811 <highlight language="config">
816 <seealso><directive module="mod_include">SSIStartTag</directive></seealso>
820 <name>SSIUndefinedEcho</name>
821 <description>String displayed when an unset variable is echoed</description>
822 <syntax>SSIUndefinedEcho <var>string</var></syntax>
823 <default>SSIUndefinedEcho "(none)"</default>
824 <contextlist><context>server config</context><context>virtual host</context>
825 <context>directory</context><context>.htaccess</context></contextlist>
826 <override>All</override>
829 <p>This directive changes the string that <module>mod_include</module>
830 displays when a variable is not set and "echoed".</p>
832 <highlight language="config">
833 SSIUndefinedEcho "<!-- undef -->"
839 <name>SSIErrorMsg</name>
840 <description>Error message displayed when there is an SSI
842 <syntax>SSIErrorMsg <var>message</var></syntax>
843 <default>SSIErrorMsg "[an error occurred while processing this
844 directive]"</default>
845 <contextlist><context>server config</context><context>virtual host</context>
846 <context>directory</context><context>.htaccess</context></contextlist>
847 <override>All</override>
850 <p>The <directive>SSIErrorMsg</directive> directive changes the error
851 message displayed when <module>mod_include</module> encounters an
852 error. For production servers you may consider changing the default
853 error message to <code>"<!-- Error -->"</code> so that
854 the message is not presented to the user.</p>
856 <p>This directive has the same effect as the <code><!--#config
857 errmsg=<var>message</var> --></code> element.</p>
859 <highlight language="config">
860 SSIErrorMsg "<!-- Error -->"
866 <name>SSIStartTag</name>
867 <description>String that starts an include element</description>
868 <syntax>SSIStartTag <var>tag</var></syntax>
869 <default>SSIStartTag "<!--#"</default>
870 <contextlist><context>server config</context><context>virtual host</context>
874 <p>This directive changes the string that <module>mod_include</module>
875 looks for to mark an include element to process.</p>
877 <p>You may want to use this option if you have 2 servers parsing the
878 output of a file each processing different commands (possibly at
879 different times).</p>
881 <highlight language="config">
882 SSIStartTag "<%"<br />
886 <p>The example given above, which also specifies a matching
887 <directive module="mod_include">SSIEndTag</directive>, will
888 allow you to use SSI directives as shown in the example
891 <example><title>SSI directives with alternate start and end tags</title>
895 <seealso><directive module="mod_include">SSIEndTag</directive></seealso>
899 <name>SSITimeFormat</name>
900 <description>Configures the format in which date strings are
901 displayed</description>
902 <syntax>SSITimeFormat <var>formatstring</var></syntax>
903 <default>SSITimeFormat "%A, %d-%b-%Y %H:%M:%S %Z"</default>
905 <context>server config</context><context>virtual host</context>
906 <context>directory</context><context>.htaccess</context></contextlist>
907 <override>All</override>
910 <p>This directive changes the format in which date strings are displayed
911 when echoing <code>DATE</code> environment variables. The
912 <var>formatstring</var> is as in <code>strftime(3)</code> from the
913 C standard library.</p>
915 <p>This directive has the same effect as the <code><!--#config
916 timefmt=<var>formatstring</var> --></code> element.</p>
918 <highlight language="config">
919 SSITimeFormat "%R, %B %d, %Y"
922 <p>The above directive would cause times to be displayed in the
923 format "22:26, June 14, 2002".</p>
929 <description>Controls whether ETags are generated by the server.</description>
930 <syntax>SSIETag on|off</syntax>
931 <default>SSIETag off</default>
932 <contextlist><context>directory</context><context>.htaccess</context></contextlist>
935 <p>Under normal circumstances, a file filtered by <module>mod_include</module>
936 may contain elements that are either dynamically generated, or that may
937 have changed independently of the original file. As a result, by default
938 the server is asked not to generate an <code>ETag</code> header for the
939 response by adding <code>no-etag</code> to the request notes.</p>
941 <p>The <directive>SSIETag</directive> directive suppresses this
942 behaviour, and allows the server to generate an <code>ETag</code> header.
943 This can be used to enable caching of the output. Note that a backend server
944 or dynamic content generator may generate an ETag of its own, ignoring
945 <code>no-etag</code>, and this ETag will be passed by
946 <module>mod_include</module> regardless of the value of this setting.
947 <directive>SSIETag</directive> can take on the following values:</p>
951 <dt><code>off</code></dt>
952 <dd><code>no-etag</code> will be added to the request notes, and the server
953 is asked not to generate an ETag. Where a server ignores the value of
954 <code>no-etag</code> and generates an ETag anyway, the ETag will be
957 <dt><code>on</code></dt>
958 <dd>Existing ETags will be respected, and ETags generated by the server will
959 be passed on in the response.</dd>
967 <name>SSILastModified</name>
968 <description>Controls whether <code>Last-Modified</code> headers are generated by the
969 server.</description>
970 <syntax>SSILastModified on|off</syntax>
971 <default>SSILastModified off</default>
972 <contextlist><context>directory</context><context>.htaccess</context></contextlist>
975 <p>Under normal circumstances, a file filtered by <module>mod_include</module>
976 may contain elements that are either dynamically generated, or that may
977 have changed independently of the original file. As a result, by default
978 the <code>Last-Modified</code> header is stripped from the response.</p>
980 <p>The <directive>SSILastModified</directive> directive overrides this
981 behaviour, and allows the <code>Last-Modified</code> header to be respected
982 if already present, or set if the header is not already present. This can
983 be used to enable caching of the output. <directive>SSILastModified</directive>
984 can take on the following values:</p>
988 <dt><code>off</code></dt>
989 <dd>The <code>Last-Modified</code> header will be stripped from responses,
990 unless the <directive module="mod_include">XBitHack</directive> directive
991 is set to <code>full</code> as described below.</dd>
993 <dt><code>on</code></dt>
994 <dd>The <code>Last-Modified</code> header will be respected if already
995 present in a response, and added to the response if the response is a
996 file and the header is missing. The
997 <directive module="mod_include">SSILastModified</directive> directive
998 takes precedence over <directive module="mod_include">XBitHack</directive>.</dd>
1003 </directivesynopsis>
1006 <name>SSILegacyExprParser</name>
1007 <description>Enable compatibility mode for conditional expressions.</description>
1008 <syntax>SSILegacyExprParser on|off</syntax>
1009 <default>SSILegacyExprParser off</default>
1010 <contextlist><context>directory</context><context>.htaccess</context></contextlist>
1011 <compatibility>Available in version 2.3.13 and later.</compatibility>
1014 <p>As of version 2.3.13, <module>mod_include</module> has switched to the
1015 new <a href="../expr.html">ap_expr</a> syntax for conditional expressions
1016 in <code>#if</code> flow control elements. This directive allows to
1017 switch to the <a href="#legacyexpr">old syntax</a> which is compatible
1018 with Apache HTTPD version 2.2.x and earlier.
1021 </directivesynopsis>
1024 <name>XBitHack</name>
1025 <description>Parse SSI directives in files with the execute bit
1027 <syntax>XBitHack on|off|full</syntax>
1028 <default>XBitHack off</default>
1029 <contextlist><context>server config</context><context>virtual host</context>
1030 <context>directory</context><context>.htaccess</context></contextlist>
1031 <override>Options</override>
1034 <p>The <directive>XBitHack</directive> directive controls the parsing
1035 of ordinary html documents. This directive only affects files associated
1036 with the <glossary>MIME-type</glossary> <code>text/html</code>. <directive
1037 >XBitHack</directive> can take on the following values:</p>
1040 <dt><code>off</code></dt>
1041 <dd>No special treatment of executable files.</dd>
1043 <dt><code>on</code></dt>
1044 <dd>Any <code>text/html</code> file that has the user-execute bit
1045 set will be treated as a server-parsed html document.</dd>
1047 <dt><code>full</code></dt>
1048 <dd>As for <code>on</code> but also test the group-execute bit.
1049 If it is set, then set the <code>Last-modified</code> date of the
1050 returned file to be the last modified time of the file. If
1051 it is not set, then no last-modified date is sent. Setting
1052 this bit allows clients and proxies to cache the result of
1055 <note><title>Note</title>
1056 <p>You would not want to use the full option, unless you assure the
1057 group-execute bit is unset for every SSI script which might <code
1058 >#include</code> a CGI or otherwise produces different output on
1059 each hit (or could potentially change on subsequent requests).</p>
1061 <p>The <directive module="mod_include">SSILastModified</directive>
1062 directive takes precedence over the
1063 <directive module="mod_include">XBitHack</directive> directive when
1064 <directive module="mod_include">SSILastModified</directive> is set to
1065 <code>on</code>.</p>
1072 </directivesynopsis>