]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_include.xml
Prelim docs
[apache] / docs / manual / mod / mod_include.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
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
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
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.
21 -->
22
23 <modulesynopsis metafile="mod_include.xml.meta">
24
25 <name>mod_include</name>
26 <description>Server-parsed html documents (Server Side Includes)</description>
27 <status>Base</status>
28 <sourcefile>mod_include.c</sourcefile>
29 <identifier>include_module</identifier>
30
31 <summary>
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>
38 </summary>
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>
43
44 <section id="enabling">
45     <title>Enabling Server-Side Includes</title>
46
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>
53
54     <highlight language="config">
55 AddType text/html .shtml
56 AddOutputFilter INCLUDES .shtml
57     </highlight>
58
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>
64     is set):</p>
65
66     <highlight language="config">
67       Options +Includes
68     </highlight>
69
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>
77
78     <p>For more information, see our <a
79     href="../howto/ssi.html">Tutorial on Server Side Includes</a>.</p>
80 </section> <!-- /enabling -->
81
82 <section id="pathinfo">
83     <title>PATH_INFO with Server Side Includes</title>
84
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 -->
91
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>
95
96     <example>
97       &lt;!--#<var>element</var> <var>attribute</var>=<var>value</var>
98       <var>attribute</var>=<var>value</var> ... --&gt;
99     </example>
100
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>--&gt;</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>&lt;!--#</code> is <em>one</em>
107     token and may not contain any whitespaces.</p>
108
109     <p>The allowed elements are listed in the following table:</p>
110
111     <table border="1">
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>
129     </table>
130
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>
136
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>
140
141       <dl>
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>
147
148       <example>
149         &lt;!--#config echomsg="[Value Undefined]" --&gt;
150       </example>
151       </dd>
152
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>
158
159       <example>
160        &lt;!--#config errmsg="[Oops, something broke.]" --&gt;
161       </example>
162       </dd>
163
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>
170
171       <example>
172       &lt;!--#config sizefmt="abbrev" --&gt;
173       </example>
174
175       </dd>
176
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
180       dates.</p>
181
182       <example>
183       &lt;!--#config timefmt=""%R, %B %d, %Y"" --&gt;
184       </example>
185
186       </dd>
187       </dl>
188     </section> <!-- /config -->
189
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>
196
197       <p>Attributes:</p>
198
199       <dl>
200       <dt><code>var</code></dt>
201       <dd>The value is the name of the variable to print.</dd>
202
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>
218
219       <p>The <code>decoding</code> attribute must <em>precede</em> the
220       corresponding <code>var</code> attribute to be effective.</p>
221       </dd>
222
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>
240
241       <p>The <code>encoding</code> attribute must <em>precede</em> the
242       corresponding <code>var</code> attribute to be effective.</p>
243
244       <note type="warning">
245         In order to avoid cross-site scripting issues, you should
246         <em>always</em> encode user supplied data.
247       </note>
248
249       <example><title>Example</title>
250         &lt;!--#echo encoding="entity" var="QUERY_STRING" --&gt;
251       </example>
252       </dd>
253       </dl>
254     </section> <!-- /echo -->
255
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>
262
263       <dl>
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>
275
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>
281
282       <example><title>Example</title>
283         &lt;!--#exec cgi="/cgi-bin/example.cgi" --&gt;
284       </example>
285
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>
288
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
294       shown here:</p>
295
296       <example>
297         &lt;!--#include virtual="/cgi-bin/example.cgi?argument=value" --&gt;
298       </example>
299       </dd>
300
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>
306
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
312       maintained.</p>
313
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>
320
321       <example>
322         &lt;!--#exec cmd="perl /path/to/perlscript arg1 arg2" --&gt;
323       </example>
324       </dd>
325       </dl>
326     </section> <!-- /exec -->
327
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>
331
332       <dl>
333       <dt><code>file</code></dt>
334       <dd>The value is a path relative to the directory
335       containing the current document being parsed.
336
337     <example>
338         This file is &lt;!--#fsize file="mod_include.html" --&gt; bytes.
339     </example>
340
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>.
346       </dd>
347
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>
353       </dl>
354
355     <example>
356         This file is &lt;!--#fsize virtual="/docs/mod/mod_include.html" --&gt; bytes.
357     </example>
358
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
361       aliases.</p>
362     </section> <!-- /fsize -->
363
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 -->
370
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>
381
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>
386
387       <dl>
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>
396
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>
403
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>
407
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>
411
412       <example>
413         &lt;!--#include virtual="/cgi-bin/example.cgi?argument=value" --&gt;
414       </example>
415
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>
419
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
425       requests.</p>
426
427       </dd>
428
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>
436
437       <example>
438         # Simple example<br />
439         &lt;!--#include virtual="/not-exist.html" onerror="/error.html" --&gt;
440       </example>
441
442       <example>
443         # Dedicated onerror paths<br />
444         &lt;!--#include virtual="/path-a.html" onerror="/error-a.html" virtual="/path-b.html" onerror="/error-b.html" --&gt;
445       </example>
446
447       </dd>
448       </dl>
449     </section> <!-- /include -->
450
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>
456
457       <example><title>Example</title>
458         &lt;pre&gt;
459           &lt;!--#printenv --&gt;
460         &lt;/pre&gt;
461       </example>
462     </section> <!-- /printenv -->
463
464     <section id="element.set"><title>The set Element</title>
465       <p>This sets the value of a variable. Attributes:</p>
466
467       <dl>
468       <dt><code>var</code></dt>
469       <dd>The name of the variable to set.</dd>
470
471       <dt><code>value</code></dt>
472       <dd>The value to give a variable.</dd>
473
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>
487       </dd>
488
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
503       stripped.</p>
504       </dd>
505       </dl>
506
507       <example><title>Example</title>
508         &lt;!--#set var="category" value="help" --&gt;
509       </example>
510     </section> <!-- /set -->
511 </section> <!-- /basic elements -->
512
513 <section id="includevars">
514     <title>Include Variables</title>
515
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>
520
521     <dl>
522       <dt><code>DATE_GMT</code></dt>
523       <dd>The current date in Greenwich Mean Time.</dd>
524
525       <dt><code>DATE_LOCAL</code></dt>
526       <dd>The current date in the local time zone.</dd>
527
528       <dt><code>DOCUMENT_NAME</code></dt>
529       <dd>The filename (excluding directories) of the document
530       requested by the user.</dd>
531
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
539       URL is shown.</dd>
540
541       <dt><code>LAST_MODIFIED</code></dt>
542       <dd>The last modification date of the document requested by
543       the user.</dd>
544
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>&amp;</code> etc. are
549       preceded by backslashes).</dd>
550     </dl>
551 </section>
552
553 <section id="substitution"><title>Variable Substitution</title>
554
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
564     quoting:</p>
565
566     <example>
567       &lt;!--#set var="cur" value="\$test" --&gt;
568     </example>
569
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>
575
576     <example>
577       &lt;!--#set var="Zed" value="${REMOTE_HOST}_${REQUEST_METHOD}" --&gt;
578     </example>
579
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>
584 </section>
585
586 <section id="flowctrl">
587     <title>Flow Control Elements</title>
588
589     <p>The basic flow control elements are:</p>
590
591     <example>
592       &lt;!--#if expr="<var>test_condition</var>" --&gt;<br />
593       &lt;!--#elif expr="<var>test_condition</var>" --&gt;<br />
594       &lt;!--#else --&gt;<br />
595       &lt;!--#endif --&gt;
596     </example>
597
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
602     output stream.</p>
603
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>
607
608     <p>The <code>endif</code> element ends the <code>if</code> element
609     and is required.</p>
610
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>
615
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>
620
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>
623
624     <example>
625       &lt;!--#if expr='-R "10.0.0.0/8"' --&gt;<br />
626       <indent>
627         from local net<br />
628       </indent>
629       &lt;!--#else --&gt;<br />
630       <indent>
631         from somewhere else<br />
632       </indent>
633       &lt;!--#endif --&gt;
634     </example>
635
636     <p>The below example will print "foo is bar" if the variable
637     <code>foo</code> is set to the value "bar".</p>
638
639     <example>
640       &lt;!--#if expr='v("foo") = "bar"' --&gt;<br />
641       <indent>
642         foo is bar<br />
643       </indent>
644       &lt;!--#endif --&gt;
645     </example>
646
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>
651     </note>
652 </section>
653
654 <section id="legacyexpr">
655     <title>Legacy expression syntax</title>
656
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>
660
661     <dl>
662       <dt><code><var>string</var></code></dt>
663       <dd>true if <var>string</var> is not empty</dd>
664
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>
671
672       <example><title>Example</title>
673         &lt;!--#if expr="-A /private" --&gt;<br />
674         <indent>
675           Click &lt;a href="/private"&gt;here&lt;/a&gt; to access private
676           information.<br />
677         </indent>
678         &lt;!--#endif --&gt;
679       </example>
680       </dd>
681
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>
685
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>
693
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>
699
700       <example><title>Example</title>
701         &lt;!--#if expr="$QUERY_STRING = /^sid=([a-zA-Z0-9]+)/" --&gt;<br />
702         <indent>
703           &lt;!--#set var="session" value="$1" --&gt;<br />
704         </indent>
705         &lt;!--#endif --&gt;
706       </example>
707       </dd>
708
709       <dt><code><var>string1</var> &lt; <var>string2</var><br />
710        <var>string1</var> &lt;= <var>string2</var><br />
711        <var>string1</var> &gt; <var>string2</var><br />
712        <var>string1</var> &gt;= <var>string2</var></code></dt>
713
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
717       "20".</dd>
718
719       <dt><code>( <var>test_condition</var> )</code></dt>
720       <dd>true if <var>test_condition</var> is true</dd>
721
722       <dt><code>! <var>test_condition</var></code></dt>
723       <dd>true if <var>test_condition</var> is false</dd>
724
725       <dt><code><var>test_condition1</var> &amp;&amp;
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>
729
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>
734     </dl>
735
736     <p>"<code>=</code>" and "<code>!=</code>" bind more tightly than
737     "<code>&amp;&amp;</code>" and "<code>||</code>". "<code>!</code>" binds
738     most tightly. Thus, the following are equivalent:</p>
739
740     <example>
741       &lt;!--#if expr="$a = test1 &amp;&amp; $b = test2" --&gt;<br />
742       &lt;!--#if expr="($a = test1) &amp;&amp; ($b = test2)" --&gt;
743     </example>
744
745     <p>The boolean operators <code>&amp;&amp;</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>
748
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>
755
756     <example>
757       <p><code><var>string1</var>&nbsp;&nbsp;&nbsp;&nbsp;<var
758       >string2</var></code> results in <code><var>string1</var>&nbsp;<var
759       >string2</var></code><br />
760       <br />
761       and<br />
762       <br />
763       <code>'<var>string1</var>&nbsp;&nbsp;&nbsp;&nbsp;<var
764       >string2</var>'</code> results in <code><var
765       >string1</var>&nbsp;&nbsp;&nbsp;&nbsp;<var>string2</var></code>.</p>
766     </example>
767
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>
772       <ul>
773       <li>Expressions are evaluated from left to right</li>
774       <li>Binary boolean operators (<code>&amp;&amp;</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
780           results.</li>
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>
784       </ul>
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>
790     </note>
791
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>
795     </note>
796
797 </section>
798
799 <directivesynopsis>
800 <name>SSIEndTag</name>
801 <description>String that ends an include element</description>
802 <syntax>SSIEndTag <var>tag</var></syntax>
803 <default>SSIEndTag &quot;--&gt;&quot;</default>
804 <contextlist><context>server config</context><context>virtual host</context>
805 </contextlist>
806
807 <usage>
808     <p>This directive changes the string that <module>mod_include</module>
809     looks for to mark the end of an include element.</p>
810
811     <highlight language="config">
812       SSIEndTag "%&gt;"
813     </highlight>
814
815 </usage>
816 <seealso><directive module="mod_include">SSIStartTag</directive></seealso>
817 </directivesynopsis>
818
819 <directivesynopsis>
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 &quot;(none)&quot;</default>
824 <contextlist><context>server config</context><context>virtual host</context>
825 <context>directory</context><context>.htaccess</context></contextlist>
826 <override>All</override>
827
828 <usage>
829     <p>This directive changes the string that <module>mod_include</module>
830     displays when a variable is not set and &quot;echoed&quot;.</p>
831
832     <highlight language="config">
833       SSIUndefinedEcho "&lt;!-- undef --&gt;"
834     </highlight>
835 </usage>
836 </directivesynopsis>
837
838 <directivesynopsis>
839 <name>SSIErrorMsg</name>
840 <description>Error message displayed when there is an SSI
841 error</description>
842 <syntax>SSIErrorMsg <var>message</var></syntax>
843 <default>SSIErrorMsg &quot;[an error occurred while processing this
844 directive]&quot;</default>
845 <contextlist><context>server config</context><context>virtual host</context>
846 <context>directory</context><context>.htaccess</context></contextlist>
847 <override>All</override>
848
849 <usage>
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>&quot;&lt;!-- Error --&gt;&quot;</code> so that
854     the message is not presented to the user.</p>
855
856     <p>This directive has the same effect as the <code>&lt;!--#config
857     errmsg=<var>message</var> --&gt;</code> element.</p>
858
859     <highlight language="config">
860       SSIErrorMsg "&lt;!-- Error --&gt;"
861     </highlight>
862 </usage>
863 </directivesynopsis>
864
865 <directivesynopsis>
866 <name>SSIStartTag</name>
867 <description>String that starts an include element</description>
868 <syntax>SSIStartTag <var>tag</var></syntax>
869 <default>SSIStartTag &quot;&lt;!--#&quot;</default>
870 <contextlist><context>server config</context><context>virtual host</context>
871 </contextlist>
872
873 <usage>
874     <p>This directive changes the string that <module>mod_include</module>
875     looks for to mark an include element to process.</p>
876
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>
880
881     <highlight language="config">
882       SSIStartTag "&lt;%"<br />
883       SSIEndTag   "%&gt;"
884     </highlight>
885
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
889     below:</p>
890
891     <example><title>SSI directives with alternate start and end tags</title>
892       &lt;%printenv %&gt;
893     </example>
894 </usage>
895 <seealso><directive module="mod_include">SSIEndTag</directive></seealso>
896 </directivesynopsis>
897
898 <directivesynopsis>
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 &quot;%A, %d-%b-%Y %H:%M:%S %Z&quot;</default>
904 <contextlist>
905 <context>server config</context><context>virtual host</context>
906 <context>directory</context><context>.htaccess</context></contextlist>
907 <override>All</override>
908
909 <usage>
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>
914
915     <p>This directive has the same effect as the <code>&lt;!--#config
916     timefmt=<var>formatstring</var> --&gt;</code> element.</p>
917
918     <highlight language="config">
919       SSITimeFormat "%R, %B %d, %Y"
920     </highlight>
921
922     <p>The above directive would cause times to be displayed in the
923     format "22:26, June 14, 2002".</p>
924 </usage>
925 </directivesynopsis>
926
927 <directivesynopsis>
928 <name>SSIETag</name>
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>
933
934 <usage>
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>
940
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>
948
949       <dl>
950
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
955           respected.</dd>
956
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>
960
961       </dl>
962
963 </usage>
964 </directivesynopsis>
965
966 <directivesynopsis>
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>
973
974 <usage>
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>
979
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>
985
986       <dl>
987
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>
992
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>
999
1000       </dl>
1001
1002 </usage>
1003 </directivesynopsis>
1004
1005 <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>
1012
1013 <usage>
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.
1019     </p>
1020 </usage>
1021 </directivesynopsis>
1022
1023 <directivesynopsis>
1024 <name>XBitHack</name>
1025 <description>Parse SSI directives in files with the execute bit
1026 set</description>
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>
1032
1033 <usage>
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>
1038
1039     <dl>
1040       <dt><code>off</code></dt>
1041       <dd>No special treatment of executable files.</dd>
1042
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>
1046
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
1053       the request.
1054
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>
1060
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>
1066       </note>
1067
1068       </dd>
1069     </dl>
1070
1071 </usage>
1072 </directivesynopsis>
1073
1074 </modulesynopsis>