ssi.html.en revision 93a89127fafc9d64767c71d81f667bf5e31c2cfd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd This file is generated from xml source: DO NOT EDIT
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<title>Apache Tutorial: Introduction to Server Side Includes - Apache HTTP Server</title>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<link href="/images/favicon.ico" rel="shortcut icon" /></head>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/faq/">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div>
4b5981e276e93df97c34e4da05ca5cf8bbd937dand<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs-project/">Documentation</a> > <a href="../">Version 2.1</a> > <a href="./">How-To / Tutorials</a></div><div id="page-content"><div id="preamble"><h1>Apache Tutorial: Introduction to Server Side Includes</h1>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<p>Server-side includes provide a means to add dynamic content to
a34d44ce259e68932a3db730a7cb0d3edde46860kessexisting HTML documents.</p>
43e2c3ca329ff3ca8cb7613d455ddb3794edf7adnd<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#related">Introduction</a></li>
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<li><img alt="" src="/images/down.gif" /> <a href="#what">What are SSI?</a></li>
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<li><img alt="" src="/images/down.gif" /> <a href="#configuring">Configuring your server to permit SSI</a></li>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<li><img alt="" src="/images/down.gif" /> <a href="#basic">Basic SSI directives</a></li>
9bcfc3697a91b5215893a7d0206865b13fc72148nd<li><img alt="" src="/images/down.gif" /> <a href="#additionalexamples">Additional examples</a></li>
9bcfc3697a91b5215893a7d0206865b13fc72148nd<li><img alt="" src="/images/down.gif" /> <a href="#config">What else can I config?</a></li>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<li><img alt="" src="/images/down.gif" /> <a href="#exec">Executing commands</a></li>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<li><img alt="" src="/images/down.gif" /> <a href="#advanced">Advanced SSI techniques</a></li>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<li><img alt="" src="/images/down.gif" /> <a href="#conclusion">Conclusion</a></li>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <table class="related"><tr><th>Related Modules</th><th>Related Directives</th></tr><tr><td><ul><li><code class="module"><a href="/mod/mod_include.html">mod_include</a></code></li><li><code class="module"><a href="/mod/mod_cgi.html">mod_cgi</a></code></li><li><code class="module"><a href="/mod/mod_expires.html">mod_expires</a></code></li></ul></td><td><ul><li><code class="directive"><a href="/mod/core.html#options">Options</a></code></li><li><code class="directive"><a href="/mod/mod_include.html#xbithack">XBitHack</a></code></li><li><code class="directive"><a href="/mod/mod_mime.html#addtype">AddType</a></code></li><li><code class="directive"><a href="/mod/core.html#setoutputfilter">SetOutputFilter</a></code></li><li><code class="directive"><a href="/mod/mod_setenvif.html#browsermatchnocase">BrowserMatchNoCase</a></code></li></ul></td></tr></table>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <p>This article deals with Server Side Includes, usually called
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd simply SSI. In this article, I'll talk about configuring your
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak server to permit SSI, and introduce some basic SSI techniques
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for adding dynamic content to your existing HTML pages.</p>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak <p>In the latter part of the article, we'll talk about some of
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd the somewhat more advanced things that can be done with SSI,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd such as conditional statements in your SSI directives.</p>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <p>SSI (Server Side Includes) are directives that are placed in
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd HTML pages, and evaluated on the server while the pages are
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd being served. They let you add dynamically generated content to
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd an existing HTML page, without having to serve the entire page
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak via a CGI program, or other dynamic technology.</p>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <p>The decision of when to use SSI, and when to have your page
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd entirely generated by some program, is usually a matter of how
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd much of the page is static, and how much needs to be
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd recalculated every time the page is served. SSI is a great way
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd to add small pieces of information, such as the current time.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd But if a majority of your page is being generated at the time
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd that it is served, you need to look for some other
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd solution.</p>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<h2><a name="configuring" id="configuring">Configuring your server to permit SSI</a></h2>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <p>To permit SSI on your server, you must have the following
0a336dd9ddab495062363310a4a4d8a0fb69c495nd directive either in your <code>httpd.conf</code> file, or in a
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd Options +Includes
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <p>This tells Apache that you want to permit files to be parsed
5383fa753e1bcd3a04ec34ba9810d671302380f2colm for SSI directives. Note that most configurations contain
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd multiple <code class="directive"><a href="/mod/core.html#options">Options</a></code> directives
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd that can override each other. You will probably need to apply the
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <code>Options</code> to the specific directory where you want SSI
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd enabled in order to assure that it gets evaluated last.</p>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <p>Not just any file is parsed for SSI directives. You have to
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd tell Apache which files should be parsed. There are two ways to
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd do this. You can tell Apache to parse any file with a
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd particular file extension, such as <code>.shtml</code>, with
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd the following directives:</p>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd AddOutputFilter INCLUDES .shtml
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <p>One disadvantage to this approach is that if you wanted to
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd add SSI directives to an existing page, you would have to
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd change the name of that page, and all links to that page, in
71fccc298df6a1540d408151a26aa22beed55d0bnd order to give it a <code>.shtml</code> extension, so that those
71fccc298df6a1540d408151a26aa22beed55d0bnd directives would be executed.</p>
71fccc298df6a1540d408151a26aa22beed55d0bnd <p>The other method is to use the <code class="directive"><a href="/mod/mod_include.html#xbithack">XBitHack</a></code> directive:</p>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak XBitHack on
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <p><code class="directive"><a href="/mod/mod_include.html#xbithack">XBitHack</a></code>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd tells Apache to parse files for SSI
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd directives if they have the execute bit set. So, to add SSI
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd directives to an existing page, rather than having to change
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak the file name, you would just need to make the file executable
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <p>A brief comment about what not to do. You'll occasionally
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd see people recommending that you just tell Apache to parse all
71fccc298df6a1540d408151a26aa22beed55d0bnd <code>.html</code> files for SSI, so that you don't have to
71fccc298df6a1540d408151a26aa22beed55d0bnd mess with <code>.shtml</code> file names. These folks have
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak perhaps not heard about <code class="directive"><a href="/mod/mod_include.html#xbithack">XBitHack</a></code>. The thing to
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak keep in mind is that, by doing this, you're requiring that
71fccc298df6a1540d408151a26aa22beed55d0bnd Apache read through every single file that it sends out to
71fccc298df6a1540d408151a26aa22beed55d0bnd clients, even if they don't contain any SSI directives. This
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd can slow things down quite a bit, and is not a good idea.</p>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <p>Of course, on Windows, there is no such thing as an execute
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd bit to set, so that limits your options a little.</p>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <p>In its default configuration, Apache does not send the last
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak modified date or content length HTTP headers on SSI pages,
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak because these values are difficult to calculate for dynamic
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd content. This can prevent your document from being cached, and
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd result in slower perceived client performance. There are two
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ways to solve this:</p>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <li>Use the <code>XBitHack Full</code> configuration. This
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd tells Apache to determine the last modified date by looking
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd only at the date of the originally requested file, ignoring
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd the modification date of any included files.</li>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <li>Use the directives provided by
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <code class="module"><a href="/mod/mod_expires.html">mod_expires</a></code> to set an explicit expiration
a34d44ce259e68932a3db730a7cb0d3edde46860kess time on your files, thereby letting browsers and proxies
a34d44ce259e68932a3db730a7cb0d3edde46860kess know that it is acceptable to cache them.</li>
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<h2><a name="basic" id="basic">Basic SSI directives</a></h2>
This document last modified <!--#flastmod file="index.html" -->
This file last modified <!--#flastmod file="ssi.shtml" -->
<!--#include virtual="/footer.html" -->
<code class="module"><a href="/mod/mod_include.html">mod_include</a></code> provides an <code>if</code>,
available to you, see the <code class="module"><a href="/mod/mod_include.html">mod_include</a></code>
<p class="apache">Maintained by the <a href="http://httpd.apache.org/docs-project/">Apache HTTP Server Documentation Project</a></p>
<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/faq/">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div>