0N/A<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
0N/A<
TITLE>Apache module mod_include</
TITLE>
0N/A<!-- Background white, links blue (unvisited), navy (visited), red (active) --> 0N/A<
H1 ALIGN="CENTER">Module mod_include</
H1>
0N/Ais compiled in by default. It provides for server-parsed html
0N/Adocuments. Several directives beyond the original NCSA definition have been
0N/Aincluded in Apache 1.2 - these are flagged below with the phrase
0N/A"Apache 1.2 and above". Of particular significance are the new flow
0N/Acontrol directives documented at the bottom.
0N/A<
H2>Enabling Server-Side Includes</
H2>
0N/AAny document with handler of "server-parsed" will be parsed by this
0N/Amodule, if the <
CODE>Includes</
CODE> option is set. If documents
0N/Acontaining server-side include directives are given the extension
0N/A.shtml, the following directives will make Apache parse them and
0N/Aassign the resulting document the mime type of <
CODE>
text/
html</
CODE>:
0N/AAddHandler server-parsed .shtml
0N/AThe following directive must be given for the directories containing
0N/Athe shtml files (typically in a <
CODE><Directory></
CODE> section,
0N/Abut this directive is also valid .htaccess files if <
CODE>AllowOverride
0N/AOptions</
CODE> is set):
0N/AAlternatively the <
A HREF="#xbithack"><
CODE>XBitHack</
CODE></
A>
0N/Adirective can be used to parse normal (<
CODE>
text/
html</
CODE>) files,
0N/Abased on file permissions. <
P>
0N/AFor backwards compatibility, documents with mime type
0N/A(and the resulting output given the mime type <
CODE>
text/
html</
CODE>).
0N/A<
H2>Basic Elements</
H2>
0N/AThe document is parsed as an HTML document, with special commands embedded
0N/Aas SGML comments. A command has the syntax:
0N/A<!--#</
CODE><
EM>element attribute=value attribute=value ...</
EM>
0N/AThe value will often be enclosed in double quotes; many commands only allow
0N/Aa single attribute-value pair. Note that the comment terminator
0N/A(<
SAMP>--></
SAMP>) should be preceded by whitespace to ensure that it
0N/Aisn't considered part of an SSI token.
0N/AThe allowed elements are:<
P>
0N/A<
DT><
STRONG>config</
STRONG>
0N/AThis command controls various aspects of the parsing. The valid attributes
0N/A<
DD>The value is a message that is sent back to the client if an error occurs
0N/Awhilst parsing the document.
0N/A<
DD>The value sets the format to be used which displaying the size of a file.
0N/AValid values are <
CODE>bytes</
CODE> for a count in bytes, or
0N/A<
CODE>abbrev</
CODE> for a count in Kb or Mb as appropriate.
0N/A<
DD>The value is a string to be used by the <
CODE>strftime(3)</
CODE> library
0N/Aroutine when printing dates.
0N/A<
DT><
STRONG>echo</
STRONG>
0N/AThis command prints one of the include variables, defined below.
0N/AIf the variable is unset, it is printed as <
CODE>(none)</
CODE>.
0N/AAny dates printed are subject to the currently configured <
CODE>timefmt</
CODE>.
0N/A<
DD>The value is the name of the variable to print.
0N/A<
DT><
STRONG>exec</
STRONG>
0N/AThe exec command executes a given shell command or CGI script.
0N/AThe IncludesNOEXEC <
A HREF="core.html#options">Option</
A> disables this command
0N/Acompletely. The valid attributes are:
0N/AThe value specifies a (%-encoded) URL relative path to the CGI script.
0N/AIf the path does not begin with a (/), then it is taken to be relative to
0N/Athe current document. The document referenced by this path is invoked
0N/Aas a CGI script, even if the server would not normally recognize it as
0N/Asuch. However, the directory containing the script must be enabled for
0N/AThe CGI script is given the PATH_INFO and query string (QUERY_STRING) of the
0N/Aoriginal request from the client; these cannot be specified in the URL path.
0N/AThe include variables will be available to the script in addition to the
0N/AIf the script returns a Location: header instead of output, then this
0N/Awill be translated into an HTML anchor.<
P>
0N/AThe <
CODE>include virtual</
CODE> element should be used in preference to
0N/A<
CODE>exec cgi</
CODE>.
0N/A<
DD>The server will execute the given string using <
CODE>/
bin/
sh</
CODE>.
0N/AThe include variables are available to the command.
0N/A<
DT><
STRONG>fsize</
STRONG>
0N/AThis command prints the size of the specified file, subject to the
0N/A<
CODE>sizefmt</
CODE> format specification. Attributes:
0N/A<
DD>The value is a path relative to the directory containing the current
0N/Adocument being parsed.
0N/A<
DD>The value is a (%-encoded) URL-path relative to the current document being
0N/Aparsed. If it does not begin with a slash (/) then it is taken to be relative
0N/Ato the current document.
0N/A<
DT><
STRONG>flastmod</
STRONG>
0N/AThis command prints the last modification date of the specified file,
0N/Asubject to the <
CODE>timefmt</
CODE> format specification. The attributes are
the same as for the <
CODE>fsize</
CODE> command.
<
DT><
STRONG>include</
STRONG>
This command inserts the text of another document or file into the parsed
file. Any included file is subject to the usual access control. If the
directory containing the parsed file has the
IncludesNOEXEC set, and the including the document would cause a program
to be executed, then it will not be included; this prevents the execution of
CGI scripts. Otherwise CGI scripts are invoked as normal using the complete
URL given in the command, including any query string.
<!--%plaintext <?INDEX CGI scripts, {\tt include} element and> --> An attribute defines the location of the document; the inclusion is done for
each attribute given to the include command. The valid attributes are:
<
DD>The value is a path relative to the directory containing the current
document being parsed. It cannot contain <
CODE>../</
CODE>, nor can it be an
absolute path. The <
CODE>virtual</
CODE> attribute should always be used
in preference to this one.
<
DD>The value is a (%-encoded) URL relative to the current document being
parsed. The URL cannot contain a scheme or hostname, only a path and
an optional query string. If it does not begin with a slash (/) then it
is taken to be relative to the current document.
A URL is constructed from the attribute, and the output the server
would return if the URL were accessed by the client is included in the parsed
output. Thus included files can be nested.
<
DT><
STRONG>printenv</
STRONG>
<
DD>This prints out a listing of all existing variables and their values.
<
DD>For example: <
CODE><!--#printenv --></
CODE>
<
DD>Apache 1.2 and above.
<
DD>This sets the value of a variable. Attributes:
<
DD>The name of the variable to set.
<
DD>The value to give a variable.
<
CODE><!--#set var="category" value="help" --></
CODE>
<
DD>Apache 1.2 and above.
<
H2>Include Variables</
H2>
In addition to the variables in the standard CGI environment, these are
available for the <
CODE>echo</
CODE> command, for <
CODE>if</
CODE> and
<
CODE>elif</
CODE>, and to any program invoked by the document.
<
DD>The current date in Greenwich Mean Time.
<
DD>The current date in the local time zone.
<
DD>The filename (excluding directories) of the document requested by the
<
DD>The (%-decoded) URL path of the document requested by the user. Note that
in the case of nested include files, this is <
EM>not</
EM> then URL for the
<
DD>The last modification date of the document requested by the user.
<
H2>Variable Substitution</
H2>
<
P> Variable substitution is done within quoted strings in most cases
where they may reasonably occur as an argument to an SSI directive.
<
SAMP>include</
SAMP>, and
directives, as well as the arguments to conditional operators.
You can insert a literal dollar sign into the string using backslash
<!--#if expr="$a = \$test" -->
<
P> If a variable reference needs to be substituted in the middle of a
character sequence that might otherwise be considered a valid
identifier in its own right, it can be disambiguated by enclosing
the reference in braces, <
EM>à la</
EM> shell substitution:
<!--#set var="Zed" value="${REMOTE_HOST}_${REQUEST_METHOD}" -->
<
P> This will result in the <
SAMP>Zed</
SAMP> variable being set to
"<
SAMP>X_Y</
SAMP>" if <
SAMP>REMOTE_HOST</
SAMP> is
"<
SAMP>X</
SAMP>" and <
SAMP>REQUEST_METHOD</
SAMP> is
"<
SAMP>Y</
SAMP>".
<
P> EXAMPLE: the below example will print "in foo" if the DOCUMENT_URI is
<!--#if expr="\"$DOCUMENT_URI\" = \"/
foo/
file.html\"" -->
<!--#elif expr="\"$DOCUMENT_URI\" = \"/
bar/
file.html\"" -->
<
H2><
A NAME="flowctrl">Flow Control Elements</
A></
H2>
These are available in Apache 1.2 and above. The basic flow control
<!--#if expr="<
EM>test_condition</
EM>" -->
<!--#elif expr="<
EM>test_condition</
EM>" -->
<
P> The <
STRONG><
CODE>if</
CODE></
STRONG> element works like an
if statement in a programming language. The test condition
is evaluated and if the result is true, then the text until
the next <
STRONG><
CODE>elif</
CODE></
STRONG>, <
STRONG><
CODE>else</
CODE></
STRONG>.
or <
STRONG><
CODE>endif</
CODE></
STRONG> element is included in the
<
P> The <
STRONG><
CODE>elif</
CODE></
STRONG> or <
STRONG><
CODE>else</
CODE></
STRONG>
statements are be used the put text into the output stream
if the original test_condition was false. These elements
<
P> The <
STRONG><
CODE>endif</
CODE></
STRONG> element ends the
<
STRONG><
CODE>if</
CODE></
STRONG> element and is required.
<
P> <
EM>test_condition</
EM> is one of the following:
<
DT><
EM>string</
EM><
DD>true if <
EM>string</
EM> is not empty
<
DT><
EM>string1</
EM> = <
EM>string2</
EM>
<
EM>string1</
EM> != <
EM>string2</
EM>
<
EM>string1</
EM> < <
EM>string2</
EM>
<
EM>string1</
EM> <= <
EM>string2</
EM>
<
EM>string1</
EM> > <
EM>string2</
EM>
<
EM>string1</
EM> >= <
EM>string2</
EM>
<
DD>Compare string1 with string 2. If string2 has the form <
EM>/string/</
EM>
then it is compared as a regular expression.
Regular expressions have the same syntax as those found in the
Unix <
SAMP>egrep</
SAMP> command.
<
DT>( <
EM>test_condition</
EM> )
<
DD>true if <
EM>test_condition</
EM> is true
<
DT>! <
EM>test_condition</
EM>
<
DD>true if <
EM>test_condition</
EM> is false
<
DT><
EM>test_condition1</
EM> && <
EM>test_condition2</
EM>
<
DD>true if both <
EM>test_condition1</
EM> and
<
EM>test_condition2</
EM> are true
<
DT><
EM>test_condition1</
EM> || <
EM>test_condition2</
EM>
<
DD>true if either <
EM>test_condition1</
EM> or
<
EM>test_condition2</
EM> is true
<
P> "<
EM>=</
EM>" and "<
EM>!=</
EM>" bind more tightly than "<
EM>&&</
EM>" and
"<
EM>!</
EM>" binds most tightly. Thus, the following are equivalent:
<!--#if expr="$a = test1 && $b = test2" -->
<!--#if expr="($a = test1) && ($b = test2)" -->
<
P> Anything that's not recognized as a variable or an operator is
treated as a string. Strings can also be quoted: <
EM>'string'</
EM>.
Unquoted strings can't contain whitespace (blanks and tabs)
because it is used to separate tokens such as variables. If
multiple strings are found in a row, they are concatenated using
<
EM>string1 string2</
EM> results in <
EM>string1 string2</
EM>
<
EM>'string1 string2'</
EM> results in <
EM>string1 string2</
EM>
<
LI><
A HREF="#xbithack">XBitHack</
A>
<
H2><
A name="xbithack">XBitHack</
A></
H2>
<!--%plaintext <?INDEX {\tt XBitHack} directive> --> ><
STRONG>Syntax:</
STRONG></
A> XBitHack <
EM>status</
EM><
BR>
><
STRONG>Default:</
STRONG></
A> <
CODE>XBitHack off</
CODE><
BR>
><
STRONG>Context:</
STRONG></
A> server config, virtual host, directory, .htaccess<
BR>
><
STRONG>Override:</
STRONG></
A> Options<
BR>
><
STRONG>Status:</
STRONG></
A> Base<
BR>
><
STRONG>Module:</
STRONG></
A> mod_include<
P>
The XBitHack directives controls the parsing of ordinary html documents.
This directive only affects files associated with the MIME type
<
EM>Status</
EM> can have the following values:
<
DD>No special treatment of executable files.
<
DD>Any file that has the user-execute bit set will be treated as a
server-parsed html document.
<
DD>As for <
CODE>on</
CODE> but also test the group-execute bit. If it
is set, then set the Last-modified date of the returned file to be the
last modified time of the file. If it is not set, then no last-modified date
is sent. Setting this bit allows clients and proxies to cache the result of
<
P><
STRONG>Note:</
STRONG> you would not want to use this, for example, when you
<
CODE>#include</
CODE> a CGI that produces different output on each hit
(or potentially depends on the hit).
<
H2>Using Server Side Includes for ErrorDocuments</
H2>
describes how to use the features of mod_include to offer internationalized
customized server error documents.