ssi.xml revision 5c3b7bef2441956c33535ed4f1c1523ffe169241
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe<manualpage>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe<title>Apache Tutorial: Introduction to Server Side Includes</title>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe<p>Server-side includes provide a means to add dynamic content to
14d5b1a7866541c4eb974f2d213d2aea59743c95wroweexisting HTML documents.</p>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe <modulelist>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe </modulelist>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe <directivelist>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe <directive module="mod_setenvif">BrowserMatchNoCase</directive>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe </directivelist>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe <p>This article deals with Server Side Includes, usually called
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe simply SSI. In this article, I'll talk about configuring your
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe server to permit SSI, and introduce some basic SSI techniques
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe for adding dynamic content to your existing HTML pages.</p>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe <p>In the latter part of the article, we'll talk about some of
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe the somewhat more advanced things that can be done with SSI,
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe such as conditional statements in your SSI directives.</p>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe <p>SSI (Server Side Includes) are directives that are placed in
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe HTML pages, and evaluated on the server while the pages are
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe being served. They let you add dynamically generated content to
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe an existing HTML page, without having to serve the entire page
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe via a CGI program, or other dynamic technology.</p>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe <p>The decision of when to use SSI, and when to have your page
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe entirely generated by some program, is usually a matter of how
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe much of the page is static, and how much needs to be
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe recalculated every time the page is served. SSI is a great way
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe to add small pieces of information, such as the current time.
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe But if a majority of your page is being generated at the time
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe that it is served, you need to look for some other
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe solution.</p>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe <p>To permit SSI on your server, you must have the following
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe directive either in your <code>httpd.conf</code> file, or in a
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe Options +Includes
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe <p>This tells Apache that you want to permit files to be parsed
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe for SSI directives. Note that most configurations contain
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe multiple <directive module="core">Options</directive> directives
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe that can override each other. You will probably need to apply the
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe <code>Options</code> to the specific directory where you want SSI
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe enabled in order to assure that it gets evaluated last.</p>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe <p>Not just any file is parsed for SSI directives. You have to
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe tell Apache which files should be parsed. There are two ways to
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe do this. You can tell Apache to parse any file with a
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe particular file extension, such as <code>.shtml</code>, with
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe the following directives:</p>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe AddOutputFilter INCLUDES .shtml
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe <p>One disadvantage to this approach is that if you wanted to
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe add SSI directives to an existing page, you would have to
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe change the name of that page, and all links to that page, in
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe order to give it a <code>.shtml</code> extension, so that those
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe directives would be executed.</p>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe module="mod_includes">XBitHack</directive> directive:</p>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe XBitHack on
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe <p><directive module="mod_includes">XBitHack</directive>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe tells Apache to parse files for SSI
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe directives if they have the execute bit set. So, to add SSI
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe directives to an existing page, rather than having to change
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe the file name, you would just need to make the file executable
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe <p>A brief comment about what not to do. You'll occasionally
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe see people recommending that you just tell Apache to parse all
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe <code>.html</code> files for SSI, so that you don't have to
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe mess with <code>.shtml</code> file names. These folks have
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe perhaps not heard about <directive
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe module="mod_includes">XBitHack</directive>. The thing to
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe keep in mind is that, by doing this, you're requiring that
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe Apache read through every single file that it sends out to
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe clients, even if they don't contain any SSI directives. This
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe can slow things down quite a bit, and is not a good idea.</p>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe <p>Of course, on Windows, there is no such thing as an execute
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe bit to set, so that limits your options a little.</p>
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe <p>In its default configuration, Apache does not send the last
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe modified date or content length HTTP headers on SSI pages,
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe because these values are difficult to calculate for dynamic
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe content. This can prevent your document from being cached, and
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe result in slower perceived client performance. There are two
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe ways to solve this:</p>
This document last modified <!--#flastmod file="index.html" -->
This file last modified <!--#flastmod file="ssi.shtml" -->
<!--#include virtual="/footer.html" -->