Home Switchboard Unix Administration Red Hat TCP/IP Networks Neoliberalism Toxic Managers
May the source be with you, but remember the KISS principle ;-)
Skepticism and critical thinking is not panacea, but can help to understand the world better

Server Side Includes (SSI)

News Recommended Links SSI Setup Converting your documents to the SSI Format SSI Environment Variables
Cheap Web hosting with SSH access     Humor Etc

Apache, NCSA HTTPd, Netscape Enterprise and several other servers  allows users to include into document other documents from the current directory and/or simple information about the document. Such information can include the current date, the file's last modification date, and the size or last modification of other files. Having the server parse documents is a double edged sword. It can be costly for heavily loaded servers to perform parsing of files while sending them and can present a security risk. Therefore documents that need to parsed usually have a default extension shtml.  User can specify  directories to allow SSI.

To a certain extent SSI can be used as a "poor man" ASP.

Taking off with the idea of SSI, several companies including Cold Fusion and Net Objects designed custom web servers with incredible SSI functionality. These third party web servers provided a huge API which offered a host of server embedded resources which app developers could use to make their web pages dynamic that extended far beyond the limited set of commands offered by the operating systems.

They also provided a huge number of formatting options as well including complex tabular display.

Cold Fusion, perhaps the best-known SSI-based application server offers a set of over 70 custom "CFML" tags that execute most, if not all of your average needs on the custom Cold Fusion Web Server. Cold Fusion also allows you to set name/value pairs in your HTML as well.



CGI Programming Chapter 5 Server Side Includes

You're starting to get the hang of CGI, but aren't too thrilled with the fact that you have to write full-fledged CGI programs even when you want to output a document with only a minimum amount of dynamic information, right? For example, say you want to display the current date and time, or a certain CGI environment variable in your otherwise static document. You can go through the trouble of writing a CGI program that outputs this small amount of virtual data, or better yet, you can use a powerful feature called Server Side Includes (or SSI).

Server Side Includes are directives which you can place into your HTML documents to execute other programs or output such data as environment variables and file statistics. Unfortunately, not all servers support these directives; the CERN server cannot handle SSI, but the servers from NCSA and Netscape can. However, there is a CGI program called that you can use to emulate Server Side Includes if your server does not support them.

While Server Side Includes technically are not really CGI, they can become an important tool for incorporating CGI-like information, as well as output from CGI programs, into documents on the Web.

How do Server Side Includes work? When the client requests a document from the SSI-enabled server, the server parses the specified document and returns the evaluated document (see Figure 5-1). The server does not automatically parse

[Mar 16, 2002] Webmaster's Guide to Server Side Includes -

[June 12, 2000] Apache Today - Apache Guide Introduction to Server Side Includes By Rich Bowen

This is the first of three articles dealing with Server Side Includes, usually called simply SSI. In this article, I'll talk about configuring your server to permit SSI and introduce some basic SSI techniques for adding dynamic content to your existing HTML pages.

In the second article, we'll talk about some of the somewhat more advanced things you can do with SSI, and in the third week, we'll look at the advanced things that can be done with SSI, such as conditional statements in your SSI directives.

What are SSI?

SSI (Server Side Includes) are directives that are placed in HTML pages and evaluated on the server while the pages are being served. They let you add dynamically generated content to an existing HTML page, without having to serve the entire page via a CGI program or other dynamic technology.

The decision of when to use SSI, and when to have your page entirely generated by some program, is usually a matter of how much of the page is static and how much needs to be recalculated every time the page is served. SSI is a great way to add small pieces of information, such as the current time. But if a majority of your page is being generated at the time that it is served, you need to look for some other solution.

Configuring Your Server to Permit SSI

To permit SSI on your server, you must have the following directive either in your httpd.conf file or in a .htaccess file:

     Options +Includes

This tells Apache that you want to permit files to be parsed for SSI directives.

Not just any file is parsed for SSI directives. You have to tell Apache which files should be parsed. There are two ways to do this. You can tell Apache to parse any file with a particular file extension, such as .shtml, with the following directives:

        AddType text/html .shtml
        AddHandler server-parsed .shtml

One disadvantage to this approach is that if you wanted to add SSI directives to an existing page, you would have to change the name of that page, and all links to that page, in order to give it a .shtml extension, so that those directives would be executed.

The other method is to use the XBitHack directive:

        XBitHack on

XBitHack tells Apache to parse files for SSI directives if they have the execute bit set. So, to add SSI directives to an existing page, rather than having to change the file name, you would just need to make the file executable using chmod.

        chmod +x pagename.html

A brief comment about what not to do. You'll occasionally see people recommending that you just tell Apache to parse all .html files for SSI, so that you don't have to mess with .shtml file names. These folks have perhaps not heard about XBitHack. The thing to keep in mind is that, by doing this, you're requiring that Apache read through every single file that it sends out to clients, even if they don't contain any SSI directives. This can slow things down quite a bit and is not a good idea.

Of course, on Windows, there is no such thing as an execute bit to set, so that limits your options a little if you're running Apache on Windows.

Basic SSI Directives

SSI directives have the following syntax:

        <!--#element attribute=value attribute=value ... -->

It is formatted like an HTML comment, so if you don't have SSI correctly enabled, the browser will ignore it, but it will still be visible in the HTML source. If you have SSI correctly configured, the directive will be replaced with the results of the directive.

The element can be one of a number of things, and we'll talk some more about most of these in the next installment of this series. For now, here are some examples of what you can do with SSI.

Today's Date

        <!--#echo var=DATE_LOCAL -->

The echo element just spits out the value of a variable. There are a number of standard variables, which include the whole set of environment variables that are available to CGI programs. Also, you can define your own variables with the set element.

If you don't like the format in which the date gets printed, you can use the config element, with a timefmt attribute, to modify that formatting.

        <!--#config timefmt="%A %B %d, %Y" -->
        Today is <!--#echo var=DATE_LOCAL -->

Modification Date of the File</4>

        This document last modified <!--#flastmod file="index.html" -->

This element is also subject to timefmt format configurations.

Including the Results of a CGI Program

This is one of the more common uses of SSI - to output the results of a CGI program, such as everybody's favorite, a hit counter.

        <!--#exec cgi="/cgi-bin/" -->

We'll definitely come back to this in another article.

[July 10, 1999] Internetter Server Side Includes Tutorial

Recommended Links

Google matched content

Softpanorama Recommended

Top articles


SSI Setup

In Apache any document with handler of "server-parsed" will be parsed for SSI, if the Includes option is set. If documents containing SSI 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
AddHandler server-parsed .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 .htaccess files if AllowOverride Options is set):

Options +Includes

Converting your documents to the SSI Format

You can use the program Perl scripts to add to you document footer and header SSI tags or other useful SSI. For adding footer and header tags Perl script exists. Usage is simple:

toshtml file.html header.html footer.html> file.shtml.

The SSI Format
(from Apache documentation)

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; 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.

The allowed elements are:

This command controls various aspects of the parsing. The valid attributes are:
The value is a message that is sent back to the client if an error occurs whilst parsing the document.
The value sets the format to be used which 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.
The value is a string to be used by the strftime(3) library routine when printing dates.
This command prints one of the include variables, defined below. If the variable is unset, it is printed as (none). Any dates printed are subject to the currently configured timefmt. Attributes:
The value is the name of the variable to print.
The exec command executes a given shell command or CGI script. The IncludesNOEXEC Option disables this command completely. The valid attributes are:
The value specifies a (%-encoded) URL relative path to the CGI script. If the path does not begin with a (/), 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 the ExecCGI Option).

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.

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 exec cgi.

The server will execute the given string using /bin/sh. The include variables are available to the command.
This command prints the size of the specified file, subject to the sizefmt format specification. Attributes:
The value is a path relative to the directory containing the current document being parsed.
The value is a (%-encoded) URL-path relative to the current document being parsed. If it does not begin with a slash (/) then it is taken to be relative to the current document.
This command prints the last modification date of the specified file, subject to the timefmt format specification. The attributes are the same as for the fsize command.
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 Option 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.

An attribute defines the location of the document; the inclusion is done for each attribute given to the include command. The valid attributes are:

The value is a path relative to the directory containing the current document being parsed. It cannot contain ../, nor can it be an absolute path. The virtual attribute should always be used in preference to this one.
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.

This prints out a listing of all existing variables and their values. No attributes.
For example: <!--#printenv -->
Apache 1.2 and above.
This sets the value of a variable. Attributes:
The name of the variable to set.
The value to give a variable.

For example: <!--#set var="category" value="help" -->

Apache 1.2 and above.

SSI Environment Variables

A number of variables are made available to parsed documents.

The current date in Greenwich Mean Time.
The current date in the local time zone.
The filename (excluding directories) of the document requested by the user.
The (%-decoded) URL path of the document requested by the user. Note that in the case of nested include files, this is not then URL for the current document.
The last modification date of the document requested by the user.


The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D

Copyright 1996-2018 by Dr. Nikolai Bezroukov. was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) in the author free time and without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.

This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

You can use PayPal to make a contribution, supporting development of this site and speed up access. In case is down you can use the at


The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.

The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.

Last modified: March 12, 2019