Skip to content Accesskey=4Skip to sub-navigation Accesskey=NView our Accessibility Options MIT Information Systems Home About IS Contact IS Site Map Search Advanced Search
Getting StartedGetting Services by Topic or Alphabetically Getting Help

Web Publishing Reference
 

Web Reference home

MIT Guidelines

Creating Web Pages

Using MIT Web Space

web.mit.edu Resources

 

Custom 404 Error page
Search Engine
Surveys
CGIemail
Custom Events Calendar
Web Use Statistics
Campus Map
Protecting Content
SSI

MIT/IS Resources

Training

Search the Web Reference:

 

Server Side Includes

The often maligned, Server Side Include can actually be very helpful in managing common page sections. Using somewhat obscure techniques you can even use SSI to control page areas that feature variable content.

Useful for

  • Static, recurring elements (i.e. headers, footers)
  • Global navigation
  • Dynamic navigation
  • Spotlights / callouts

Common complaints

  • I use dreamweaver, why bother with library items and templates?
  • I use dreamweaver and I like the WSIWYG mode
  • When am I ever going to update those parts of my site anyway?
  • I don't want to name my files .shtml and break links

Rebuttal

  • It's faster and more reliable
  • Newer versions of dreamweaver can display SSIs
  • You'd be surprised, ever see a copyright statement like this:
    "Copyright (c) 1995-2001 Massachusetts Institute of Technology"?
  • Ahh, but you don't have to...see "XBitHack" below

SSI lets you embed a number of special 'commands' into the HTML such as displaying when a file was last modified, inserting another HTML file, or echoing a string of characters when an 'if' expression is true.

The most common use for SSI is to have the same footer display on every page. The footer is a separate file that gets pulled in by the server when a browser requests a web page with an included footer. We will use this page as an example. To create an included footer, create an HTML file called footer.html with the footer information you want. To insert this footer into your page, add the following code at the end of the document

<!--#include file="footer.html" -->

Then name your page with the extension .shtml instead of .html or .htm. To see your file with the footer included, view the .shtml file in a browser. If you name a file index.shtml in a directory, and no index.html is present, index.shtml will load as the default page for that directory. The syntax is similar for other includes.

XBitHack

By default any file with the extension .shtml will be processed as a file that contains SSI instructions. The main MIT web servers (http://web.mit.edu/) have the Apache XBitHack directive enabled. This directive allows content providers to specify using UNIX file permissions which files should be parsed for SSI —regardless of the file extension. If you have a file, index.html that has SSI instructions in it you can enable SSI processing with out changing the file extension by executing the folowing statement via the Athena command line interface:

athena:~ www$ chmod 755 index.html

Processing all files in a directory structure as SSI files

There is a way to process your files as SSI files without using the .shtml extension. To have all .html files in a particular directory structure parsed for server side include instructions, you can place a .htaccess.mit file at the top-most Athena directory of your choosing. This file (which may also contain instructions for securing content via MIT certificates or instructions for creating a custom 404 error page) must contain the following line:

 AddHandler server-parsed .html 

You can change .html to any file extension (i.e. .htm) as long as they are files intended to be processed as if they were .shtml.

Other options that are available with the include module on web.mit.edu:

Server Side Include Options
Task Syntax
include a file <!--#include file="footer.html" -->
include a "virtual" file <!--#include virtual="/spotlight.html" -->
echo <!--#echo var="DOCUMENT_URI" -->
yields /ist/web/reference/web-resources/ssi.shtml
time format <!--#config timefmt="%A, %B %d, %Y at %r %Z" -->
<!--#echo var="LAST_MODIFIED" -->

yields Wednesday, December 15, 1999 at 10:30:49 PM EST
flastmod <!--#flastmod file="test-ssi.shtml" -->
yields Wednesday, December 15, 1999 at 10:12:08 PM EST
virtual flastmod <!--#flastmod virtual="/spotlight.html" -->
if expr <!--#if expr="$REMOTE_ADDR = /^18./" -->
< !--#echo var="REMOTE_ADDR" -->

The "exec" feature of server-side includes is disabled, so you can't run scripts or commands from them.

The following common environment variables can be used in #if and #echo statements, e.g.
<!--#echo var="HTTP_USER_AGENT" -->.

DOCUMENT_ROOT
HTTP_USER_AGENT (provides browser type and OS if possible)
REQUEST_URI
SERVER_ADDR
SERVER_SOFTWARE (provides version of software running on web server)
DATE_GMT (provides current date in Greenwich Mean Time)
DATE_LOCAL (provides current date in the local time zone)
DOCUMENT_NAME (provides filename--excluding directories--of the document requested by the user)
DOCUMENT_URI (provides %-decoded URL path of the document requested by the user)
LAST_MODIFIED (provides last modification date of the document requested by the user)

The full list of variables you can use for the #if and #echo commands is available from ssi-echo.shtml. More information about server side includes is available from Apache Week and Apache.org.

MIT Home | Getting Started | Getting Services | Getting Help | About IS&T | Accessibility
Ask a technology question or send a comment about this web page.