Server Side Includes (SSI) Usage
SSI lets you embed a number of special 'commands' into the HTML,
such as when a file was last modified, including 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 brower requests web page with an included footer. 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" -->
and 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.
Other options that are available with the include module on
web.mit.edu:
| Syntax | |
| include a file | <!--#include file="footer.html" --> |
| include a "virtual" file | <!--#include virtual="/spotlight.html" --> |
| echo |
<!--#echo var="DOCUMENT_URI" --> yields /cwis/web/ssi-usage.shtml |
| time format |
<!--#config timefmt="%A, %B %d, %Y at %r %Z" -->
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.
Features provided by web.mit.edu
Comments to
web-request@mit.edu