Text of httpd.apache.org › docs › current › mod › mod_include.html as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

mod_include - Apache HTTP Server Version 2.4

Modules | Directives | FAQ | Glossary | Sitemap | Report a bug Apache HTTP Server Version 2.4 Apache > HTTP Server > Documentation > Version 2.4 > Modules Apache Module mod_include Available Languages: en | fr | ja Description: Server-parsed html documents (Server Side Includes) Status: Base Module Identifier: include_module Source File: mod_include.c Summary This module provides a filter which will process files before they are sent to the client.

The processing is controlled by specially formatted SGML comments, referred to as elements . These elements allow conditional text, the inclusion of other files or programs, as well as the setting and printing of environment variables. Topics Enabling Server-Side Includes PATH_INFO with Server Side Includes Available Elements Include Variables Variable Substitution Flow Control Elements Legacy expression syntax Directives SSIEndTag SSIErrorMsg SSIETag SSILastModified SSILegacyExprParser SSIStartTag SSITimeFormat SSIUndefinedEcho XBitHack Bugfix checklist httpd changelog Known issues Report a bug See also Options AcceptPathInfo Filters SSI Tutorial Enabling Server-Side Includes ¶ Server Side Includes are implemented by the INCLUDES filter .

If documents containing server-side include directives are given the extension .shtml, the following directives will make Apache parse them and assign the resulting document the mime type of text/html : AddType text/html .shtml AddOutputFilter INCLUDES .shtml The following directive must be given for the directories containing the shtml files (typically in a <Directory> section, but this directive is also valid in .htaccess files if AllowOverride Options is set): Options +Includes For backwards compatibility, the server-parsed handler also activates the INCLUDES filter.

As well, Apache will activate the INCLUDES filter for any document with mime type text/x-server-parsed-html or text/x-server-parsed-html3 (and the resulting output will have the mime type text/html ). For more information, see our Tutorial on Server Side Includes . PATH_INFO with Server Side Includes ¶ Files processed for server-side includes no longer accept requests with PATH_INFO (trailing pathname information) by default.

You can use the AcceptPathInfo directive to configure the server to accept requests with PATH_INFO . Available Elements ¶ The document is parsed as an HTML document, with special commands embedded as SGML comments. A command has the syntax: <!--# element attribute = value attribute = value ... --> The value will often be enclosed in double quotes, but single quotes ( ' ) and backticks ( ` ) are also possible. Many commands only allow a single attribute-value pair.

Note that the comment terminator ( --> ) should be preceded by whitespace to ensure that it isn't considered part of an SSI token. Note that the leading <!--# is one token and may not contain any whitespaces. The allowed elements are listed in the following table: Element Description comment SSI comment config configure output formats echo print variables exec execute external programs fsize print size of a file flastmod print last modification time of a file include include a file printenv print all available variables set set a value of a variable SSI elements may be defined by modules other than mod_include .

In fact, the exec element is provided by mod_cgi , and will only be available if this module is loaded. The comment Element This command doesn't output anything. Its only use is to add comments within a file. These comments are not printed. This syntax is available in version 2.4.21 and later. <!--#comment Blah Blah Blah --> or <!--#comment text="Blah Blah Blah" --> The config Element This command controls various aspects of the parsing.

The valid attributes are: echomsg ( Apache 2.1 and later ) The value is a message that is sent back to the client if the echo element attempts to echo an undefined variable. This overrides any SSIUndefinedEcho directives. <!--#config echomsg="[Value Undefined]" --> errmsg The value is a message that is sent back to the client if an error occurs while parsing the document. This overrides any SSIErrorMsg directives. <!--#config errmsg="[Oops, something broke.]" --> sizefmt The value sets the format to be used when displaying the size of a file.

Valid values are bytes for a count in bytes, or abbrev for a count in Kb or Mb as appropriate, for example a size of 1024 bytes will be printed as "1K". <!--#config sizefmt="abbrev" --> timefmt The value is a string to be used by the strftime(3) library routine when printing dates. <!--#config timefmt=""%R, %B %d, %Y"" --> The echo Element This command prints one of the include variables defined below. If the variable is unset, the result is determined by the SSIUndefinedEcho directive.

Any dates printed are subject to the currently configured timefmt . Attributes: var The value is the name of the variable to print. decoding Specifies whether Apache should strip an encoding from the variable before processing the variable further. The default is none , where no decoding will be done. If set to url , then URL decoding (also known as %-encoding; this is appropriate for use within URLs in links, etc.) will be performed.

If set to urlencoded , application/x-www-form-urlencoded compatible encoding (found in query strings) will be stripped. If set to base64 , base64 will be decoded, and if set to entity , HTML entity encoding will be stripped. Decoding is done prior to any further encoding on the variable. Multiple encodings can be stripped by specifying more than one comma separated encoding. The decoding setting will remain in effect until the next decoding attribute is encountered, or the element ends.

The decoding attribute must precede the corresponding var attribute to be effective. encoding Specifies how Apache should encode special characters contained in the variable before outputting them. If set to none , no encoding will be done. If set to url , then URL encoding (also known as %-encoding; this is appropriate for use within URLs in links, etc.) will be performed. If set to urlencoded , application/x-www-form-urlencoded compatible encoding will be performed instead, and should be used with query strings.

If set to base64 , base64 encoding will be performed. At the start of an echo element, the default is set to entity , resulting in entity encoding (which is appropriate in the context of a block-level HTML element, e.g. a paragraph of text). This can be changed by adding an encoding attribute, which will remain in effect until the next encoding attribute is encountered or the element ends, whichever comes first. The encoding attribute must precede the corresponding var attribute to be effective.

In order to avoid cross-site scripting issues, you should always encode user supplied data. Example <!--#echo encoding="entity" var="QUERY_STRING" --> The exec Element The exec command executes a given shell command or CGI script. It requires mod_cgi to be present in the server. If Options IncludesNOEXEC is set, this command is completely disabled. The valid attributes are: cgi The value specifies a (%-encoded) URL-path to the CGI script.

If the path does not begin with a slash (/), then it is taken to be relative to the current document. The document referenced by this path is invoked as a CGI script, even if the server would not normally recognize it as such. However, the directory containing the script must be enabled for CGI scripts (with ScriptAlias or Options ExecCGI ). The CGI script is given the PATH_INFO and query string ( QUERY_STRING ) of the original request from the client; these cannot be specified in the URL path.

The include variables will be available to the script in addition to the standard CGI environment. Example <!--#exec cgi="/cgi-bin/example.cgi" --> If the script returns a Location: header instead of output, then this will be translated into an HTML anchor. The include virtual element should be used in preference to ex

The rest of this page is on the live site.