]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_include.xml
Fixes to XML. rebuild.
[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 <compatibility>Implemented as an output filter since Apache
31 2.0</compatibility>
32
33 <summary>
34     <p>This module provides a filter which will process files
35     before they are sent to the client. The processing is
36     controlled by specially formatted SGML comments, referred to as
37     <dfn>elements</dfn>. These elements allow conditional text, the
38     inclusion of other files or programs, as well as the setting and
39     printing of environment variables.</p>
40 </summary>
41 <seealso><directive module="core">Options</directive></seealso>
42 <seealso><directive module="core">AcceptPathInfo</directive></seealso>
43 <seealso><a href="../filter.html">Filters</a></seealso>
44 <seealso><a href="../howto/ssi.html">SSI Tutorial</a></seealso>
45
46 <section id="enabling">
47     <title>Enabling Server-Side Includes</title>
48
49     <p>Server Side Includes are implemented by the
50     <code>INCLUDES</code> <a href="../filter.html">filter</a>. If
51     documents containing server-side include directives are given
52     the extension .shtml, the following directives will make Apache
53     parse them and assign the resulting document the mime type of
54     <code>text/html</code>:</p>
55
56     <highlight language="config">
57 AddType text/html .shtml
58 AddOutputFilter INCLUDES .shtml
59     </highlight>
60
61     <p>The following directive must be given for the directories
62     containing the shtml files (typically in a
63     <directive module="core" type="section">Directory</directive> section,
64     but this directive is also valid in <code>.htaccess</code> files if
65     <directive module="core">AllowOverride</directive> <code>Options</code>
66     is set):</p>
67
68     <highlight language="config">
69       Options +Includes
70     </highlight>
71
72     <p>For backwards compatibility, the <code>server-parsed</code>
73     <a href="../handler.html">handler</a> also activates the
74     INCLUDES filter. As well, Apache will activate the INCLUDES
75     filter for any document with mime type
76     <code>text/x-server-parsed-html</code> or
77     <code>text/x-server-parsed-html3</code> (and the resulting
78     output will have the mime type <code>text/html</code>).</p>
79
80     <p>For more information, see our <a
81     href="../howto/ssi.html">Tutorial on Server Side Includes</a>.</p>
82 </section> <!-- /enabling -->
83
84 <section id="pathinfo">
85     <title>PATH_INFO with Server Side Includes</title>
86
87     <p>Files processed for server-side includes no longer accept
88     requests with <code>PATH_INFO</code> (trailing pathname information)
89     by default.  You can use the <directive
90     module="core">AcceptPathInfo</directive> directive to
91     configure the server to accept requests with <code>PATH_INFO</code>.</p>
92 </section> <!-- /pathinfo -->
93
94 <section id="elements"><title>Basic Elements</title>
95     <p>The document is parsed as an HTML document, with special
96     commands embedded as SGML comments. A command has the syntax: </p>
97
98     <example>
99       &lt;!--#<var>element</var> <var>attribute</var>=<var>value</var>
100       <var>attribute</var>=<var>value</var> ... --&gt;
101     </example>
102
103     <p>The value will often be enclosed in double quotes, but single
104     quotes (<code>'</code>) and backticks (<code>`</code>) are also
105     possible. Many commands only allow a single attribute-value pair.
106     Note that the comment terminator (<code>--&gt;</code>) should be
107     preceded by whitespace to ensure that it isn't considered part of
108     an SSI token. Note that the leading <code>&lt;!--#</code> is <em>one</em>
109     token and may not contain any whitespaces.</p>
110
111     <p>The allowed elements are listed in the following table:</p>
112
113     <table border="1">
114     <tr><th>Element</th><th>Description</th></tr>
115     <tr><td><code><a href="#element.config">config</a></code></td>
116         <td>configure output formats</td></tr>
117     <tr><td><code><a href="#element.echo">echo</a></code></td>
118         <td>print variables</td></tr>
119     <tr><td><code><a href="#element.exec">exec</a></code></td>
120         <td>execute external programs</td></tr>
121     <tr><td><code><a href="#element.fsize">fsize</a></code></td>
122         <td>print size of a file</td></tr>
123     <tr><td><code><a href="#element.flastmod">flastmod</a></code></td>
124         <td>print last modification time of a file</td></tr>
125     <tr><td><code><a href="#element.include">include</a></code></td>
126         <td>include a file</td></tr>
127     <tr><td><code><a href="#element.printenv">printenv</a></code></td>
128         <td>print all available variables</td></tr>
129     <tr><td><code><a href="#element.set">set</a></code></td>
130         <td>set a value of a variable</td></tr>
131     </table>
132
133     <p>SSI elements may be defined by modules other than
134     <module>mod_include</module>. In fact, the <code><a
135     href="#element.exec">exec</a></code> element is provided by
136     <module>mod_cgi</module>, and will only be available if this
137     module is loaded.</p>
138
139     <section id="element.config"><title>The config Element</title>
140       <p>This command controls various aspects of the parsing. The
141       valid attributes are:</p>
142
143       <dl>
144       <dt><code>echomsg</code> (<em>Apache 2.1 and later</em>)</dt>
145       <dd>The value is a message that is sent back to the
146       client if the <code><a href="#element.echo">echo</a></code> element
147       attempts to echo an undefined variable. This overrides any <directive
148       module="mod_include">SSIUndefinedEcho</directive> directives.</dd>
149
150       <dt><code>errmsg</code></dt>
151       <dd>The value is a message that is sent back to the
152       client if an error occurs while parsing the
153       document. This overrides any <directive
154       module="mod_include">SSIErrorMsg</directive> directives.</dd>
155
156       <dt><code>sizefmt</code></dt>
157       <dd>The value sets the format to be used when displaying
158       the size of a file. Valid values are <code>bytes</code>
159       for a count in bytes, or <code>abbrev</code> for a count
160       in Kb or Mb as appropriate, for example a size of 1024 bytes
161       will be printed as "1K".</dd>
162
163       <dt><code>timefmt</code></dt>
164       <dd>The value is a string to be used by the
165       <code>strftime(3)</code> library routine when printing
166       dates.</dd>
167       </dl>
168     </section> <!-- /config -->
169
170     <section id="element.echo"><title>The echo Element</title>
171       <p>This command prints one of the <a href="#includevars">include
172       variables</a> defined below. If the variable is unset, the result is
173       determined by the <directive module="mod_include"
174       >SSIUndefinedEcho</directive> directive. Any dates printed are
175       subject to the currently configured <code>timefmt</code>.</p>
176
177       <p>Attributes:</p>
178
179       <dl>
180       <dt><code>var</code></dt>
181       <dd>The value is the name of the variable to print.</dd>
182
183       <dt><code>decoding</code></dt>
184       <dd><p>Specifies whether Apache should strip an encoding from
185       the variable before processing the variable further. The default
186       is <code>none</code>, where no decoding will be done. If set to
187       <code>url</code>, then URL decoding (also known as %-encoding;
188       this is appropriate for use within URLs in links, etc.) will be
189       performed. If set to <code>urlencoded</code>,
190       application/x-www-form-urlencoded compatible encoding (found in
191       query strings) will be stripped. If set to <code>base64</code>,
192       base64 will be decoded, and if set to <code>entity</code>, HTML
193       entity encoding will be stripped. Decoding is done prior to any
194       further encoding on the variable. Multiple encodings can be
195       stripped by specifying more than one comma separated encoding.
196       The decoding setting will remain in effect until the next decoding
197       attribute is encountered, or the element ends.</p>
198
199       <p>The <code>decoding</code> attribute must <em>precede</em> the
200       corresponding <code>var</code> attribute to be effective.</p>
201       </dd>
202
203       <dt><code>encoding</code></dt>
204       <dd><p>Specifies how Apache should encode special characters
205       contained in the variable before outputting them. If set
206       to <code>none</code>, no encoding will be done. If set to
207       <code>url</code>, then URL encoding (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 will be
211       performed instead, and should be used with query strings. If set
212       to <code>base64</code>, base64 encoding will be performed. At
213       the start of an <code>echo</code> element, the default is set to
214       <code>entity</code>, resulting in entity encoding (which is
215       appropriate in the context of a block-level HTML element,
216       <em>e.g.</em> a paragraph of text). This can be changed by adding
217       an <code>encoding</code> attribute, which will remain in effect
218       until the next <code>encoding</code> attribute is encountered or
219       the element ends, whichever comes first.</p>
220
221       <p>The <code>encoding</code> attribute must <em>precede</em> the
222       corresponding <code>var</code> attribute to be effective.</p>
223
224       <note type="warning">
225         In order to avoid cross-site scripting issues, you should
226         <em>always</em> encode user supplied data.
227       </note>
228       </dd>
229       </dl>
230     </section> <!-- /echo -->
231
232     <section id="element.exec"><title>The exec Element</title>
233       <p>The <code>exec</code> command executes a given shell command or
234       CGI script. It requires <module>mod_cgi</module> to be present
235       in the server. If <directive module="core">Options</directive>
236       <code>IncludesNOEXEC</code> is set, this command is completely
237       disabled. The valid attributes are:</p>
238
239       <dl>
240       <dt><code>cgi</code></dt>
241       <dd><p>The value specifies a (%-encoded) URL-path to
242       the CGI script. If the path does not begin with a slash (/),
243       then it is taken to be relative to the current
244       document. The document referenced by this path is
245       invoked as a CGI script, even if the server would not
246       normally recognize it as such. However, the directory
247       containing the script must be enabled for CGI scripts
248       (with <directive module="mod_alias">ScriptAlias</directive>
249       or <directive module="core">Options</directive>
250       <code>ExecCGI</code>).</p>
251
252       <p>The CGI script is given the <code>PATH_INFO</code> and query
253       string (<code>QUERY_STRING</code>) of the original request from the
254       client; these <em>cannot</em> be specified in the URL path. The
255       include variables will be available to the script in addition to
256       the standard <a href="mod_cgi.html">CGI</a> environment.</p>
257
258       <example><title>Example</title>
259         &lt;!--#exec cgi="/cgi-bin/example.cgi" --&gt;
260       </example>
261
262       <p>If the script returns a <code>Location:</code> header instead of
263       output, then this will be translated into an HTML anchor.</p>
264
265       <p>The <code><a href="#includevirtual">include virtual</a></code>
266       element should be used in preference to <code>exec cgi</code>. In
267       particular, if you need to pass additional arguments to a CGI program,
268       using the query string, this cannot be done with <code>exec
269       cgi</code>, but can be done with <code>include virtual</code>, as
270       shown here:</p>
271
272       <example>
273         &lt;!--#include virtual="/cgi-bin/example.cgi?argument=value" --&gt;
274       </example>
275       </dd>
276
277       <dt><code>cmd</code></dt>
278       <dd><p>The server will execute the given string using
279       <code>/bin/sh</code>. The <a href="#includevars"
280       >include variables</a> are available to the command, in addition
281       to the usual set of CGI variables.</p>
282
283       <p>The use of <code><a href="#includevirtual"
284       >#include virtual</a></code> is almost always prefered to using
285       either <code>#exec cgi</code> or <code>#exec cmd</code>. The former
286       (<code>#include virtual</code>) uses the standard Apache sub-request
287       mechanism to include files or scripts. It is much better tested and
288       maintained.</p>
289
290       <p>In addition, on some platforms, like Win32, and on unix when
291       using <a href="../suexec.html">suexec</a>, you cannot pass arguments
292       to a command in an <code>exec</code> directive, or otherwise include
293       spaces in the command. Thus, while the following will work under a
294       non-suexec configuration on unix, it will not produce the desired
295       result under Win32, or when running suexec:</p>
296
297       <example>
298         &lt;!--#exec cmd="perl /path/to/perlscript arg1 arg2" --&gt;
299       </example>
300       </dd>
301       </dl>
302     </section> <!-- /exec -->
303
304     <section id="element.fsize"><title>The fsize Element</title>
305       <p>This command prints the size of the specified file, subject
306       to the <code>sizefmt</code> format specification. Attributes:</p>
307
308       <dl>
309       <dt><code>file</code></dt>
310       <dd>The value is a path relative to the directory
311       containing the current document being parsed.</dd>
312
313       <dt><code>virtual</code></dt>
314       <dd>The value is a (%-encoded) URL-path. If it does not begin with
315       a slash (/) then it is taken to be relative to the current document.
316       Note, that this does <em>not</em> print the size of any CGI output,
317       but the size of the CGI script itself.</dd>
318       </dl>
319     </section> <!-- /fsize -->
320
321     <section id="element.flastmod"><title>The flastmod Element</title>
322       <p>This command prints the last modification date of the
323       specified file, subject to the <code>timefmt</code> format
324       specification. The attributes are the same as for the
325       <code><a href="#element.fsize">fsize</a></code> command.</p>
326     </section> <!-- /flastmod -->
327
328     <section id="element.include"><title>The include Element</title>
329       <p>This command inserts the text of another document or file
330       into the parsed file. Any included file is subject to the usual
331       access control. If the directory containing the parsed file has
332       <a href="core.html#options">Options</a>
333       <code>IncludesNOEXEC</code> set, then only documents with a text
334       <glossary>MIME-type</glossary> (<code>text/plain</code>,
335       <code>text/html</code> etc.) will be included. Otherwise CGI
336       scripts are invoked as normal using the complete URL given in
337       the command, including any query string.</p>
338
339       <p>An attribute defines the location of the document, and may
340       appear more than once in an include element; an inclusion is
341       done for each attribute given to the include command in turn.
342       The valid attributes are:</p>
343
344       <dl>
345       <dt><code>file</code></dt>
346       <dd>The value is a path relative to the directory
347       containing the current document being parsed. It cannot
348       contain <code>../</code>, nor can it be an absolute path.
349       Therefore, you cannot include files that are outside of the
350       document root, or above the current document in the directory
351       structure. The <code>virtual</code> attribute should always be
352       used in preference to this one.</dd>
353
354       <dt><code><a id="includevirtual" name="includevirtual"
355       >virtual</a></code></dt>
356       <dd><p>The value is a (%-encoded) URL-path. The URL cannot contain a
357       scheme or hostname, only a path and an optional query string. If it
358       does not begin with a slash (/) then it is taken to be relative to the
359       current document.</p>
360
361       <p>A URL is constructed from the attribute, and the output the
362       server would return if the URL were accessed by the client is
363       included in the parsed output. Thus included files can be nested.</p>
364
365       <p>If the specified URL is a CGI program, the program will be
366       executed and its output inserted in place of the directive in the
367       parsed file. You may include a query string in a CGI url:</p>
368
369       <example>
370         &lt;!--#include virtual="/cgi-bin/example.cgi?argument=value" --&gt;
371       </example>
372
373       <p><code>include virtual</code> should be used in preference
374       to <code>exec cgi</code> to include the output of CGI programs
375       into an HTML document.</p>
376
377       <p>If the <directive module="mod_request">KeptBodySize</directive>
378       directive is correctly configured and valid for this included
379       file, attempts to POST requests to the enclosing HTML document
380       will be passed through to subrequests as POST requests as well.
381       Without the directive, all subrequests are processed as GET
382       requests.</p>
383
384       </dd>
385
386       <dt><code>onerror</code></dt>
387       <dd><p>The value is a (%-encoded) URL-path which is shown should a
388       previous attempt to include a file or virtual attribute failed.
389       To be effective, this attribute must be specified after the
390       file or virtual attributes being covered. If the attempt to
391       include the onerror path fails, or if onerror is not specified, the
392       default error message will be included.</p>
393
394       <example>
395         # Simple example<br />
396         &lt;!--#include virtual="/not-exist.html" onerror="/error.html" --&gt;
397       </example>
398
399       <example>
400         # Dedicated onerror paths<br />
401         &lt;!--#include virtual="/path-a.html" onerror="/error-a.html" virtual="/path-b.html" onerror="/error-b.html" --&gt;
402       </example>
403
404       </dd>
405       </dl>
406     </section> <!-- /include -->
407
408     <section id="element.printenv"><title>The printenv Element</title>
409       <p>This prints out a listing of all existing variables and
410       their values. Special characters are entity encoded (see the <code><a
411       href="#element.echo">echo</a></code> element for details)
412       before being output. There are no attributes.</p>
413
414       <example><title>Example</title>
415         &lt;!--#printenv --&gt;
416       </example>
417     </section> <!-- /printenv -->
418
419     <section id="element.set"><title>The set Element</title>
420       <p>This sets the value of a variable. Attributes:</p>
421
422       <dl>
423       <dt><code>var</code></dt>
424       <dd>The name of the variable to set.</dd>
425
426       <dt><code>value</code></dt>
427       <dd>The value to give a variable.</dd>
428
429       <dt><code>decoding</code></dt>
430       <dd><p>Specifies whether Apache should strip an encoding from
431       the variable before processing the variable further. The default
432       is <code>none</code>, where no decoding will be done. If set to
433       <code>url</code>, <code>urlencoded</code>, <code>base64</code>
434       or <code>entity</code>, URL decoding,
435       application/x-www-form-urlencoded decoding, base64 decoding or HTML
436       entity decoding will be performed respectively. More than one
437       decoding can be specified by separating with commas. The decoding
438       setting will remain in effect until the next decoding attribute
439       is encountered, or the element ends. The <code>decoding</code>
440       attribute must <em>precede</em> the corresponding
441       <code>var</code> attribute to be effective.</p>
442       </dd>
443
444       <dt><code>encoding</code></dt>
445       <dd><p>Specifies how Apache should encode special characters
446       contained in the variable before setting them. The default is
447       <code>none</code>, where no encoding will be done. If set to
448       <code>url</code>, <code>urlencoding</code>, <code>base64</code>
449       or <code>entity</code>, URL encoding,
450       application/x-www-form-urlencoded encoding, base64 encoding or
451       HTML entity encoding will be performed respectively. More than
452       one encoding can be specified by separating with commas. The
453       encoding setting will remain in effect until the next encoding
454       attribute is encountered, or the element ends. The
455       <code>encoding</code> attribute must <em>precede</em> the
456       corresponding <code>var</code> attribute to be effective.
457       Encodings are applied after all decodings have been
458       stripped.</p>
459       </dd>
460       </dl>
461
462       <example><title>Example</title>
463         &lt;!--#set var="category" value="help" --&gt;
464       </example>
465     </section> <!-- /set -->
466 </section> <!-- /basic elements -->
467
468 <section id="includevars">
469     <title>Include Variables</title>
470
471     <p>In addition to the variables in the standard CGI environment,
472     these are available for the <code>echo</code> command, for
473     <code>if</code> and <code>elif</code>, and to any program
474     invoked by the document.</p>
475
476     <dl>
477       <dt><code>DATE_GMT</code></dt>
478       <dd>The current date in Greenwich Mean Time.</dd>
479
480       <dt><code>DATE_LOCAL</code></dt>
481       <dd>The current date in the local time zone.</dd>
482
483       <dt><code>DOCUMENT_NAME</code></dt>
484       <dd>The filename (excluding directories) of the document
485       requested by the user.</dd>
486
487       <dt><code>DOCUMENT_URI</code></dt>
488       <dd>The (%-decoded) URL path of the document requested by the
489       user. Note that in the case of nested include files, this is
490       <em>not</em> the URL for the current document.  Note also that
491       if the URL is modified internally (e.g. by an <directive
492       module="mod_alias">alias</directive> or <directive
493       module="mod_dir">directoryindex</directive>), the modified
494       URL is shown.</dd>
495
496       <dt><code>LAST_MODIFIED</code></dt>
497       <dd>The last modification date of the document requested by
498       the user.</dd>
499
500       <dt><code>QUERY_STRING_UNESCAPED</code></dt>
501       <dd>If a query string is present, this variable contains the
502       (%-decoded) query string, which is <em>escaped</em> for shell
503       usage (special characters like <code>&amp;</code> etc. are
504       preceded by backslashes).</dd>
505     </dl>
506 </section>
507
508 <section id="substitution"><title>Variable Substitution</title>
509
510     <p>Variable substitution is done within quoted strings in most
511     cases where they may reasonably occur as an argument to an SSI
512     directive. This includes the <code>config</code>,
513     <code>exec</code>, <code>flastmod</code>, <code>fsize</code>,
514     <code>include</code>, <code>echo</code>, and <code>set</code>
515     directives. If <directive module="mod_include"
516     >SSILegacyExprParser</directive> is set to <code>on</code>,
517     substitution also occures in the arguments to conditional operators.
518     You can insert a literal dollar sign into the string using backslash
519     quoting:</p>
520
521     <example>
522       &lt;!--#set var="cur" value="\$test" --&gt;
523     </example>
524
525     <p>If a variable reference needs to be substituted in the
526     middle of a character sequence that might otherwise be
527     considered a valid identifier in its own right, it can be
528     disambiguated by enclosing the reference in braces,
529     <em>a la</em> shell substitution:</p>
530
531     <example>
532       &lt;!--#set var="Zed" value="${REMOTE_HOST}_${REQUEST_METHOD}" --&gt;
533     </example>
534
535     <p>This will result in the <code>Zed</code> variable being set
536     to "<code>X_Y</code>" if <code>REMOTE_HOST</code> is
537     "<code>X</code>" and <code>REQUEST_METHOD</code> is
538     "<code>Y</code>".</p>
539 </section>
540
541 <section id="flowctrl">
542     <title>Flow Control Elements</title>
543
544     <p>The basic flow control elements are:</p>
545
546     <example>
547       &lt;!--#if expr="<var>test_condition</var>" --&gt;<br />
548       &lt;!--#elif expr="<var>test_condition</var>" --&gt;<br />
549       &lt;!--#else --&gt;<br />
550       &lt;!--#endif --&gt;
551     </example>
552
553     <p>The <code>if</code> element works like an if statement in a
554     programming language. The test condition is evaluated and if
555     the result is true, then the text until the next <code>elif</code>,
556     <code>else</code> or <code>endif</code> element is included in the
557     output stream.</p>
558
559     <p>The <code>elif</code> or <code>else</code> statements are used
560     to put text into the output stream if the original
561     <var>test_condition</var> was false. These elements are optional.</p>
562
563     <p>The <code>endif</code> element ends the <code>if</code> element
564     and is required.</p>
565
566     <p><var>test_condition</var> is a boolean expression tha follows the
567     <a href="../expr.html">ap_expr</a> syntax. The syntax can be changed
568     to be compatible with Apache HTTPD 2.2.x using <directive
569     module="mod_include">SSILegacyExprParser</directive>.</p>
570
571     <p>The SSI variables set with the <code>var</code> element are exported
572     into the request environment and can be accessed with the
573     <code>reqenv</code> function. As a short-cut, the function name
574     <code>v</code> is also available inside <module>mod_include</module>.</p>
575
576     <p>The below example will print "from local net" if client IP address
577     belongs to the 10.0.0.0/8 subnet.</p>
578
579     <example>
580       &lt;!--#if expr='-R "10.0.0.0/8"' --&gt;<br />
581       <indent>
582         from local net<br />
583       </indent>
584       &lt;!--#else --&gt;<br />
585       <indent>
586         from somewhere else<br />
587       </indent>
588       &lt;!--#endif --&gt;
589     </example>
590
591     <p>The below example will print "foo is bar" if the variable
592     <code>foo</code> is set to the value "bar".</p>
593
594     <example>
595       &lt;!--#if expr='v("foo") = "bar"' --&gt;<br />
596       <indent>
597         foo is bar<br />
598       </indent>
599       &lt;!--#endif --&gt;
600     </example>
601
602     <note><title>Reference Documentation</title>
603     <p>See also: <a href="../expr.html">Expressions in Apache HTTP Server</a>,
604     for a complete reference and examples. The <em>restricted</em> functions
605     are not available inside <module>mod_include</module></p>
606     </note>
607 </section>
608
609 <section id="legacyexpr">
610     <title>Legacy expression syntax</title>
611
612     <p>This section describes the syntax of the <code>#if expr</code>
613     element if <directive module="mod_include">SSILegacyExprParser</directive>
614     is set to <code>on</code>.</p>
615
616     <dl>
617       <dt><code><var>string</var></code></dt>
618       <dd>true if <var>string</var> is not empty</dd>
619
620       <dt><code><var>-A string</var></code></dt>
621       <dd><p>true if the URL represented by the string is accessible by
622       configuration, false otherwise. This is useful where content on a
623       page is to be hidden from users who are not authorized to view the
624       URL, such as a link to that URL. Note that the URL is only tested
625       for whether access would be granted, not whether the URL exists.</p>
626
627       <example><title>Example</title>
628         &lt;!--#if expr="-A /private" --&gt;<br />
629         <indent>
630           Click &lt;a href="/private"&gt;here&lt;/a&gt; to access private
631           information.<br />
632         </indent>
633         &lt;!--#endif --&gt;
634       </example>
635       </dd>
636
637       <dt><code><var>string1</var> = <var>string2</var><br />
638       <var>string1</var> == <var>string2</var><br />
639       <var>string1</var> != <var>string2</var></code></dt>
640
641       <dd><p>Compare <var>string1</var> with <var>string2</var>. If
642       <var>string2</var> has the form <code>/<var>string2</var>/</code>
643       then it is treated as a regular expression. Regular expressions are
644       implemented by the <a href="http://www.pcre.org">PCRE</a> engine and
645       have the same syntax as those in <a href="http://www.perl.com">perl
646       5</a>. Note that <code>==</code> is just an alias for <code>=</code>
647       and behaves exactly the same way.</p>
648
649       <p>If you are matching positive (<code>=</code> or <code>==</code>), you
650       can capture grouped parts of the regular expression. The captured parts
651       are stored in the special variables <code>$1</code> ..
652       <code>$9</code>. The whole string matched by the regular expression is
653       stored in the special variable <code>$0</code></p>
654
655       <example><title>Example</title>
656         &lt;!--#if expr="$QUERY_STRING = /^sid=([a-zA-Z0-9]+)/" --&gt;<br />
657         <indent>
658           &lt;!--#set var="session" value="$1" --&gt;<br />
659         </indent>
660         &lt;!--#endif --&gt;
661       </example>
662       </dd>
663
664       <dt><code><var>string1</var> &lt; <var>string2</var><br />
665        <var>string1</var> &lt;= <var>string2</var><br />
666        <var>string1</var> &gt; <var>string2</var><br />
667        <var>string1</var> &gt;= <var>string2</var></code></dt>
668
669       <dd>Compare <var>string1</var> with <var>string2</var>. Note, that
670       strings are compared <em>literally</em> (using
671       <code>strcmp(3)</code>). Therefore the string "100" is less than
672       "20".</dd>
673
674       <dt><code>( <var>test_condition</var> )</code></dt>
675       <dd>true if <var>test_condition</var> is true</dd>
676
677       <dt><code>! <var>test_condition</var></code></dt>
678       <dd>true if <var>test_condition</var> is false</dd>
679
680       <dt><code><var>test_condition1</var> &amp;&amp;
681         <var>test_condition2</var></code></dt>
682       <dd>true if both <var>test_condition1</var> and
683       <var>test_condition2</var> are true</dd>
684
685       <dt><code><var>test_condition1</var> ||
686         <var>test_condition2</var></code></dt>
687       <dd>true if either <var>test_condition1</var> or
688       <var>test_condition2</var> is true</dd>
689     </dl>
690
691     <p>"<code>=</code>" and "<code>!=</code>" bind more tightly than
692     "<code>&amp;&amp;</code>" and "<code>||</code>". "<code>!</code>" binds
693     most tightly. Thus, the following are equivalent:</p>
694
695     <example>
696       &lt;!--#if expr="$a = test1 &amp;&amp; $b = test2" --&gt;<br />
697       &lt;!--#if expr="($a = test1) &amp;&amp; ($b = test2)" --&gt;
698     </example>
699
700     <p>The boolean operators <code>&amp;&amp;</code> and <code>||</code>
701     share the same priority. So if you want to bind such an operator more
702     tightly, you should use parentheses.</p>
703
704     <p>Anything that's not recognized as a variable or an operator
705     is treated as a string. Strings can also be quoted:
706     <code>'string'</code>. Unquoted strings can't contain whitespace
707     (blanks and tabs) because it is used to separate tokens such as
708     variables. If multiple strings are found in a row, they are
709     concatenated using blanks. So,</p>
710
711     <example>
712       <p><code><var>string1</var>&nbsp;&nbsp;&nbsp;&nbsp;<var
713       >string2</var></code> results in <code><var>string1</var>&nbsp;<var
714       >string2</var></code><br />
715       <br />
716       and<br />
717       <br />
718       <code>'<var>string1</var>&nbsp;&nbsp;&nbsp;&nbsp;<var
719       >string2</var>'</code> results in <code><var
720       >string1</var>&nbsp;&nbsp;&nbsp;&nbsp;<var>string2</var></code>.</p>
721     </example>
722
723     <note><title>Optimization of Boolean Expressions</title>
724       <p>If the expressions become more complex and slow down processing
725       significantly, you can try to optimize them according to the
726       evaluation rules:</p>
727       <ul>
728       <li>Expressions are evaluated from left to right</li>
729       <li>Binary boolean operators (<code>&amp;&amp;</code> and <code>||</code>)
730           are short circuited wherever possible. In conclusion with the rule
731           above that means, <module>mod_include</module> evaluates at first
732           the left expression. If the left result is sufficient to determine
733           the end result, processing stops here. Otherwise it evaluates the
734           right side and computes the end result from both left and right
735           results.</li>
736       <li>Short circuit evaluation is turned off as long as there are regular
737           expressions to deal with. These must be evaluated to fill in the
738           backreference variables (<code>$1</code> .. <code>$9</code>).</li>
739       </ul>
740       <p>If you want to look how a particular expression is handled, you can
741       recompile <module>mod_include</module> using the
742       <code>-DDEBUG_INCLUDE</code> compiler option. This inserts for every
743       parsed expression tokenizer information, the parse tree and how it is
744       evaluated into the output sent to the client.</p>
745     </note>
746
747     <note><title>Escaping slashes in regex strings</title>
748      <p>All slashes which are not intended to act as delimiters in your regex must
749      be escaped.  This is regardless of their meaning to the regex engine.</p>
750     </note>
751
752 </section>
753
754 <directivesynopsis>
755 <name>SSIEndTag</name>
756 <description>String that ends an include element</description>
757 <syntax>SSIEndTag <var>tag</var></syntax>
758 <default>SSIEndTag &quot;--&gt;&quot;</default>
759 <contextlist><context>server config</context><context>virtual host</context>
760 </contextlist>
761 <compatibility>Available in version 2.0.30 and later.</compatibility>
762
763 <usage>
764     <p>This directive changes the string that <module>mod_include</module>
765     looks for to mark the end of an include element.</p>
766
767     <highlight language="config">
768       SSIEndTag "%&gt;"
769     </highlight>
770
771 </usage>
772 <seealso><directive module="mod_include">SSIStartTag</directive></seealso>
773 </directivesynopsis>
774
775 <directivesynopsis>
776 <name>SSIUndefinedEcho</name>
777 <description>String displayed when an unset variable is echoed</description>
778 <syntax>SSIUndefinedEcho <var>string</var></syntax>
779 <default>SSIUndefinedEcho &quot;(none)&quot;</default>
780 <contextlist><context>server config</context><context>virtual host</context>
781 <context>directory</context><context>.htaccess</context></contextlist>
782 <override>All</override>
783 <compatibility>Available in version 2.0.34 and later.</compatibility>
784
785 <usage>
786     <p>This directive changes the string that <module>mod_include</module>
787     displays when a variable is not set and &quot;echoed&quot;.</p>
788
789     <highlight language="config">
790       SSIUndefinedEcho "&lt;!-- undef --&gt;"
791     </highlight>
792 </usage>
793 </directivesynopsis>
794
795 <directivesynopsis>
796 <name>SSIErrorMsg</name>
797 <description>Error message displayed when there is an SSI
798 error</description>
799 <syntax>SSIErrorMsg <var>message</var></syntax>
800 <default>SSIErrorMsg &quot;[an error occurred while processing this
801 directive]&quot;</default>
802 <contextlist><context>server config</context><context>virtual host</context>
803 <context>directory</context><context>.htaccess</context></contextlist>
804 <override>All</override>
805 <compatibility>Available in version 2.0.30 and later.</compatibility>
806
807 <usage>
808     <p>The <directive>SSIErrorMsg</directive> directive changes the error
809     message displayed when <module>mod_include</module> encounters an
810     error. For production servers you may consider changing the default
811     error message to <code>&quot;&lt;!-- Error --&gt;&quot;</code> so that
812     the message is not presented to the user.</p>
813
814     <p>This directive has the same effect as the <code>&lt;!--#config
815     errmsg=<var>message</var> --&gt;</code> element.</p>
816
817     <highlight language="config">
818       SSIErrorMsg "&lt;!-- Error --&gt;"
819     </highlight>
820 </usage>
821 </directivesynopsis>
822
823 <directivesynopsis>
824 <name>SSIStartTag</name>
825 <description>String that starts an include element</description>
826 <syntax>SSIStartTag <var>tag</var></syntax>
827 <default>SSIStartTag &quot;&lt;!--#&quot;</default>
828 <contextlist><context>server config</context><context>virtual host</context>
829 </contextlist>
830 <compatibility>Available in version 2.0.30 and later.</compatibility>
831
832 <usage>
833     <p>This directive changes the string that <module>mod_include</module>
834     looks for to mark an include element to process.</p>
835
836     <p>You may want to use this option if you have 2 servers parsing the
837     output of a file each processing different commands (possibly at
838     different times).</p>
839
840     <highlight language="config">
841       SSIStartTag "&lt;%"<br />
842       SSIEndTag   "%&gt;"
843     </highlight>
844
845     <p>The example given above, which also specifies a matching
846     <directive module="mod_include">SSIEndTag</directive>, will
847     allow you to use SSI directives as shown in the example
848     below:</p>
849
850     <example><title>SSI directives with alternate start and end tags</title>
851       &lt;%printenv %&gt;
852     </example>
853 </usage>
854 <seealso><directive module="mod_include">SSIEndTag</directive></seealso>
855 </directivesynopsis>
856
857 <directivesynopsis>
858 <name>SSITimeFormat</name>
859 <description>Configures the format in which date strings are
860 displayed</description>
861 <syntax>SSITimeFormat <var>formatstring</var></syntax>
862 <default>SSITimeFormat &quot;%A, %d-%b-%Y %H:%M:%S %Z&quot;</default>
863 <contextlist>
864 <context>server config</context><context>virtual host</context>
865 <context>directory</context><context>.htaccess</context></contextlist>
866 <override>All</override>
867 <compatibility>Available in version 2.0.30 and later.</compatibility>
868
869 <usage>
870 <p>This directive changes the format in which date strings are displayed
871     when echoing <code>DATE</code> environment variables. The
872     <var>formatstring</var> is as in <code>strftime(3)</code> from the
873     C standard library.</p>
874
875     <p>This directive has the same effect as the <code>&lt;!--#config
876     timefmt=<var>formatstring</var> --&gt;</code> element.</p>
877
878     <highlight language="config">
879       SSITimeFormat "%R, %B %d, %Y"
880     </highlight>
881
882     <p>The above directive would cause times to be displayed in the
883     format "22:26, June 14, 2002".</p>
884 </usage>
885 </directivesynopsis>
886
887 <directivesynopsis>
888 <name>SSIETag</name>
889 <description>Controls whether ETags are generated by the server.</description>
890 <syntax>SSIETag on|off</syntax>
891 <default>SSIETag off</default>
892 <contextlist><context>directory</context><context>.htaccess</context></contextlist>
893 <compatibility>Available in version 2.2.15 and later.</compatibility>
894
895 <usage>
896       <p>Under normal circumstances, a file filtered by <module>mod_include</module>
897         may contain elements that are either dynamically generated, or that may
898         have changed independently of the original file. As a result, by default
899         the server is asked not to generate an <code>ETag</code> header for the
900         response by adding <code>no-etag</code> to the request notes.</p>
901
902       <p>The <directive>SSIETag</directive> directive suppresses this
903         behaviour, and allows the server to generate an <code>ETag</code> header.
904         This can be used to enable caching of the output. Note that a backend server
905         or dynamic content generator may generate an ETag of its own, ignoring
906         <code>no-etag</code>, and this ETag will be passed by
907         <module>mod_include</module> regardless of the value of this setting.
908         <directive>SSIETag</directive> can take on the following values:</p>
909
910       <dl>
911
912         <dt><code>off</code></dt>
913         <dd><code>no-etag</code> will be added to the request notes, and the server
914           is asked not to generate an ETag. Where a server ignores the value of
915           <code>no-etag</code> and generates an ETag anyway, the ETag will be
916           respected.</dd>
917
918         <dt><code>on</code></dt>
919         <dd>Existing ETags will be respected, and ETags generated by the server will
920           be passed on in the response.</dd>
921
922       </dl>
923
924 </usage>
925 </directivesynopsis>
926
927 <directivesynopsis>
928 <name>SSILastModified</name>
929 <description>Controls whether <code>Last-Modified</code> headers are generated by the
930 server.</description>
931 <syntax>SSILastModified on|off</syntax>
932 <default>SSILastModified off</default>
933 <contextlist><context>directory</context><context>.htaccess</context></contextlist>
934 <compatibility>Available in version 2.2.15 and later.</compatibility>
935
936 <usage>
937       <p>Under normal circumstances, a file filtered by <module>mod_include</module>
938         may contain elements that are either dynamically generated, or that may
939         have changed independently of the original file. As a result, by default
940         the <code>Last-Modified</code> header is stripped from the response.</p>
941
942       <p>The <directive>SSILastModified</directive> directive overrides this
943         behaviour, and allows the <code>Last-Modified</code> header to be respected
944         if already present, or set if the header is not already present. This can
945         be used to enable caching of the output. <directive>SSILastModified</directive>
946         can take on the following values:</p>
947
948       <dl>
949
950         <dt><code>off</code></dt>
951         <dd>The <code>Last-Modified</code> header will be stripped from responses,
952           unless the <directive module="mod_include">XBitHack</directive> directive
953           is set to <code>full</code> as described below.</dd>
954
955         <dt><code>on</code></dt>
956         <dd>The <code>Last-Modified</code> header will be respected if already
957           present in a response, and added to the response if the response is a
958           file and the header is missing. The
959           <directive module="mod_include">SSILastModified</directive> directive
960           takes precedence over <directive module="mod_include">XBitHack</directive>.</dd>
961
962       </dl>
963
964 </usage>
965 </directivesynopsis>
966
967 <directivesynopsis>
968 <name>SSILegacyExprParser</name>
969 <description>Enable compatibility mode for conditional expressions.</description>
970 <syntax>SSILegacyExprParser on|off</syntax>
971 <default>SSILegacyExprParser off</default>
972 <contextlist><context>directory</context><context>.htaccess</context></contextlist>
973 <compatibility>Available in version 2.3.13 and later.</compatibility>
974
975 <usage>
976     <p>As of version 2.3.13, <module>mod_include</module> has switched to the
977     new <a href="../expr.html">ap_expr</a> syntax for conditional expressions
978     in <code>#if</code> flow control elements.  This directive allows to
979     switch to the <a href="#legacyexpr">old syntax</a> which is compatible
980     with Apache HTTPD version 2.2.x and earlier.
981     </p>
982 </usage>
983 </directivesynopsis>
984
985 <directivesynopsis>
986 <name>XBitHack</name>
987 <description>Parse SSI directives in files with the execute bit
988 set</description>
989 <syntax>XBitHack on|off|full</syntax>
990 <default>XBitHack off</default>
991 <contextlist><context>server config</context><context>virtual host</context>
992 <context>directory</context><context>.htaccess</context></contextlist>
993 <override>Options</override>
994
995 <usage>
996     <p>The <directive>XBitHack</directive> directive controls the parsing
997     of ordinary html documents. This directive only affects files associated
998     with the <glossary>MIME-type</glossary> <code>text/html</code>. <directive
999     >XBitHack</directive> can take on the following values:</p>
1000
1001     <dl>
1002       <dt><code>off</code></dt>
1003       <dd>No special treatment of executable files.</dd>
1004
1005       <dt><code>on</code></dt>
1006       <dd>Any <code>text/html</code> file that has the user-execute bit
1007       set will be treated as a server-parsed html document.</dd>
1008
1009       <dt><code>full</code></dt>
1010       <dd>As for <code>on</code> but also test the group-execute bit.
1011       If it is set, then set the <code>Last-modified</code> date of the
1012       returned file to be the last modified time of the file. If
1013       it is not set, then no last-modified date is sent. Setting
1014       this bit allows clients and proxies to cache the result of
1015       the request.
1016
1017       <note><title>Note</title>
1018       <p>You would not want to use the full option, unless you assure the
1019       group-execute bit is unset for every SSI script which might <code
1020       >#include</code> a CGI or otherwise produces different output on
1021       each hit (or could potentially change on subsequent requests).</p>
1022
1023       <p>The <directive module="mod_include">SSILastModified</directive>
1024       directive takes precedence over the
1025       <directive module="mod_include">XBitHack</directive> directive when
1026       <directive module="mod_include">SSILastModified</directive> is set to
1027       <code>on</code>.</p>
1028       </note>
1029
1030       </dd>
1031     </dl>
1032
1033 </usage>
1034 </directivesynopsis>
1035
1036 </modulesynopsis>
1037