CU Home
Columbia University Information Technology
Server Side Includes

Web Design > Server Side Includes

Server-side includes are directives that can be placed in your HTML file, telling the web server to include additional information in the displayed document. This feature is most often used to display the size of a file before downloading, or the date last modified of the current document. In addition, you can use the include element to insert common header files, or trailer files, in your web documents. You can then change the header file and the trailer file without changing all the documents that include them.

Enabling SSI

If your web document contains SSI directives you must use one of these methods to enable SSI.
  • Turn on the user execute bit by changing the file protection. This is the best way to enable SSI functionality if you have just a single file that uses ssi. For example, if you have a file called schedule.html that contains SSI directives, use this command:

    $ chmod u+x schedule.html

  • Another way to enable SSI is to use the .shtml file extension, instead of .html. (Other web servers may use a different naming convention. These instructions are specific to Columbia Web.)

  • Lastly, and the best solution if you have more than one document using ssi, create a file named .htaccess containing the following line:

    AddHandler server-parsed html

    The .htaccess file should reside in the same directory as your files that require ssi functionality. Don't forget to include the dot at the beginning of your file name.
The SSI directives are treated as comments by web authoring software, since they use this syntax:

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

The value will often be enclosed in double quotes; many commands only allow a single attribute-value pair. Here are some typical examples that use the echo element:

<!--#echo var="date_local" -->
<!--#echo var="remote_host" -->
<!--#echo var="remote_user" -->

Using include will allow you to include the content of another file into your current document. For example, if we wanted to include an email address and a copyright notice at the bottom of all of our web pages, we could create a file named footer.html that contained this information and "include" it into all of our pages. If the email address changes, or we wish to add something else to the footer in the pages on our site, we only have to change the content of one file instead of every page — very efficient and convenient. At the bottom of each of our pages we would put

<!--#include virtual="/acis/ourpages/bits/footer.html" -->

An attribute, using either "virtual" or "file," defines the location of the file we want to include:
  • virtual gives a virtual path to a document on the server that is a (%-encoded) URL relative to the current document being parsed (displayed in the web browser). The URL cannot contain a scheme or hostname (eg. columbia.edu), 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.
  • file gives a pathname relative to the directory containing the current document being parsed. You cannot use ../ (go up a directory) in this pathname, nor an absolute path.
It is usually best to use virtual.


« Back to Interactivity and Design Continue to SSI Quick Reference »