C and S Design.
Search Friendly Programming and Design



SSI Include Directive

This is not intended to be a complete tutorial on SSI, but as an explanation to the one directive that gets used the most.

<!--#include file="filename"-->
For SSI the server needs to be configured to process the required document extensions as SSI enabled documents. By default .shtml and .shtm are the file extensions used for SSI on IIS (Windows based servers) and .shtml on Apache servers. With IIS SSI is enabled by default and disabled with Apache. To configure an Apache server to parse for SSI there is a SSI tutorial on the Apache site.

Only the document that is the intended target for the includes needs to be the one parsed for directives, The file that is being included can be any text document.

The Include Directive

Two variations of the directive can be used

<!--#include file=...-->
and
<!--#include virtual=...-->
The two directives serve identical functions for different situations.
If the included file is in a subfolder or is in the same folder relative to the current document the #include file argument is used and if the included file is in a folder above the current document, the #include virtual argument is used. The file argument cannot be used to go up the folder tree by using <!--#include file="../filename"-->

for example using this folder structure

root---- www
        |----include
        |      |
        |      |---header.htm
        |      |---style.css
        |
         ---reports
              |---index.shtml    
              |---report.htm
              |
               --- include
                    |---footer.txt

To have index.shtml include header.htm, report.htm and footer.txt the page code would be

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Reports Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="description" content="Reports page">
<meta name="keywords" content="keywords">
<link href="/include/style.css" rel="stylesheet" type="text/css">
</head>

<body>

<!--#include virtual="/include/header.htm"-->
<!--#include file="report.htm"-->
<!--#include file="include/footer.txt"-->

</body>
</html>


Valid HTML 4.01! Valid CSS! copyright © C and S Design 2004 - 2005
Website Design and SE Friendly Coding C and S Design