⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ssi.html.en

📁 apache的软件linux版本
💻 EN
📖 第 1 页 / 共 2 页
字号:
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX              This file is generated from xml source: DO NOT EDIT        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX      --><title>Apache Tutorial: Introduction to Server Side Includes - Apache HTTP Server</title><link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" /><link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" /><link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link href="../images/favicon.ico" rel="shortcut icon" /></head><body id="manual-page"><div id="page-header"><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><p class="apache">Apache HTTP Server Version 2.0</p><img alt="" src="../images/feather.gif" /></div><div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div><div id="path"><a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.0</a> &gt; <a href="./">How-To / Tutorials</a></div><div id="page-content"><div id="preamble"><h1>Apache Tutorial: Introduction to Server Side Includes</h1><div class="toplang"><p><span>Available Languages: </span><a href="../en/howto/ssi.html" title="English">&nbsp;en&nbsp;</a> |<a href="../ja/howto/ssi.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |<a href="../ko/howto/ssi.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a></p></div><p>Server-side includes provide a means to add dynamic content toexisting HTML documents.</p></div><div id="quickview"><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#related">Introduction</a></li><li><img alt="" src="../images/down.gif" /> <a href="#what">What are SSI?</a></li><li><img alt="" src="../images/down.gif" /> <a href="#configuring">Configuring your server to permit SSI</a></li><li><img alt="" src="../images/down.gif" /> <a href="#basic">Basic SSI directives</a></li><li><img alt="" src="../images/down.gif" /> <a href="#additionalexamples">Additional examples</a></li><li><img alt="" src="../images/down.gif" /> <a href="#config">What else can I config?</a></li><li><img alt="" src="../images/down.gif" /> <a href="#exec">Executing commands</a></li><li><img alt="" src="../images/down.gif" /> <a href="#advanced">Advanced SSI techniques</a></li><li><img alt="" src="../images/down.gif" /> <a href="#conclusion">Conclusion</a></li></ul></div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2><a name="related" id="related">Introduction</a></h2> <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>    <p>This article deals with Server Side Includes, usually called    simply SSI. In this article, I'll talk about configuring your    server to permit SSI, and introduce some basic SSI techniques    for adding dynamic content to your existing HTML pages.</p>    <p>In the latter part of the article, we'll talk about some of    the somewhat more advanced things that can be done with SSI,    such as conditional statements in your SSI directives.</p></div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2><a name="what" id="what">What are SSI?</a></h2>    <p>SSI (Server Side Includes) are directives that are placed in    HTML pages, and evaluated on the server while the pages are    being served. They let you add dynamically generated content to    an existing HTML page, without having to serve the entire page    via a CGI program, or other dynamic technology.</p>    <p>The decision of when to use SSI, and when to have your page    entirely generated by some program, is usually a matter of how    much of the page is static, and how much needs to be    recalculated every time the page is served. SSI is a great way    to add small pieces of information, such as the current time.    But if a majority of your page is being generated at the time    that it is served, you need to look for some other    solution.</p></div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2><a name="configuring" id="configuring">Configuring your server to permit SSI</a></h2>    <p>To permit SSI on your server, you must have the following    directive either in your <code>httpd.conf</code> file, or in a    <code>.htaccess</code> file:</p><div class="example"><p><code>        Options +Includes</code></p></div>    <p>This tells Apache that you want to permit files to be parsed    for SSI directives.  Note that most configurations contain    multiple <code class="directive"><a href="../mod/core.html#options">Options</a></code> directives    that can override each other.  You will probably need to apply the    <code>Options</code> to the specific directory where you want SSI    enabled in order to assure that it gets evaluated last.</p>    <p>Not just any file is parsed for SSI directives. You have to    tell Apache which files should be parsed. There are two ways to    do this. You can tell Apache to parse any file with a    particular file extension, such as <code>.shtml</code>, with    the following directives:</p><div class="example"><p><code>        AddType text/html .shtml<br />	AddOutputFilter INCLUDES .shtml</code></p></div>    <p>One disadvantage to this approach is that if you wanted to    add SSI directives to an existing page, you would have to    change the name of that page, and all links to that page, in    order to give it a <code>.shtml</code> extension, so that those    directives would be executed.</p>    <p>The other method is to use the <code class="directive"><a href="../mod/mod_include.html#xbithack">XBitHack</a></code> directive:</p><div class="example"><p><code>        XBitHack on</code></p></div>    <p><code class="directive"><a href="../mod/mod_include.html#xbithack">XBitHack</a></code>    tells Apache to parse files for SSI    directives if they have the execute bit set. So, to add SSI    directives to an existing page, rather than having to change    the file name, you would just need to make the file executable    using <code>chmod</code>.</p><div class="example"><p><code>        chmod +x pagename.html</code></p></div>    <p>A brief comment about what not to do. You'll occasionally    see people recommending that you just tell Apache to parse all    <code>.html</code> files for SSI, so that you don't have to    mess with <code>.shtml</code> file names. These folks have    perhaps not heard about <code class="directive"><a href="../mod/mod_include.html#xbithack">XBitHack</a></code>. The thing to    keep in mind is that, by doing this, you're requiring that    Apache read through every single file that it sends out to    clients, even if they don't contain any SSI directives. This    can slow things down quite a bit, and is not a good idea.</p>    <p>Of course, on Windows, there is no such thing as an execute    bit to set, so that limits your options a little.</p>    <p>In its default configuration, Apache does not send the last    modified date or content length HTTP headers on SSI pages,    because these values are difficult to calculate for dynamic    content. This can prevent your document from being cached, and    result in slower perceived client performance. There are two    ways to solve this:</p>    <ol>      <li>Use the <code>XBitHack Full</code> configuration. This      tells Apache to determine the last modified date by looking      only at the date of the originally requested file, ignoring      the modification date of any included files.</li>      <li>Use the directives provided by       <code class="module"><a href="../mod/mod_expires.html">mod_expires</a></code> to set an explicit expiration      time on your files, thereby letting browsers and proxies      know that it is acceptable to cache them.</li>    </ol></div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2><a name="basic" id="basic">Basic SSI directives</a></h2>    <p>SSI directives have the following syntax:</p><div class="example"><p><code>        &lt;!--#element attribute=value attribute=value ... --&gt;</code></p></div>    <p>It is formatted like an HTML comment, so if you don't have    SSI correctly enabled, the browser will ignore it, but it will    still be visible in the HTML source. If you have SSI correctly    configured, the directive will be replaced with its    results.</p>    <p>The element can be one of a number of things, and we'll talk    some more about most of these in the next installment of this    series. For now, here are some examples of what you can do with    SSI</p><h3><a name="todaysdate" id="todaysdate">Today's date</a></h3><div class="example"><p><code>        &lt;!--#echo var="DATE_LOCAL" --&gt;</code></p></div>    <p>The <code>echo</code> element just spits out the value of a    variable. There are a number of standard variables, which    include the whole set of environment variables that are    available to CGI programs. Also, you can define your own    variables with the <code>set</code> element.</p>    <p>If you don't like the format in which the date gets printed,    you can use the <code>config</code> element, with a    <code>timefmt</code> attribute, to modify that formatting.</p><div class="example"><p><code>        &lt;!--#config timefmt="%A %B %d, %Y" --&gt;<br />        Today is &lt;!--#echo var="DATE_LOCAL" --&gt;</code></p></div><h3><a name="lastmodified" id="lastmodified">Modification date of the file</a></h3><div class="example"><p><code>        This document last modified &lt;!--#flastmod file="index.html" --&gt;</code></p></div>    <p>This element is also subject to <code>timefmt</code> format    configurations.</p><h3><a name="cgi" id="cgi">Including the results of a CGI program</a></h3>    <p>This is one of the more common uses of SSI - to output the    results of a CGI program, such as everybody's favorite, a ``hit    counter.''</p><div class="example"><p><code>        &lt;!--#include virtual="/cgi-bin/counter.pl" --&gt;</code></p></div></div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2><a name="additionalexamples" id="additionalexamples">Additional examples</a></h2>    <p>Following are some specific examples of things you can do in    your HTML documents with SSI.</p><h3><a name="docmodified" id="docmodified">When was this documentmodified?</a></h3>    <p>Earlier, we mentioned that you could use SSI to inform the    user when the document was most recently modified. However, the    actual method for doing that was left somewhat in question. The    following code, placed in your HTML document, will put such a    time stamp on your page. Of course, you will have to have SSI    correctly enabled, as discussed above.</p><div class="example"><p><code>        &lt;!--#config timefmt="%A %B %d, %Y" --&gt;<br />        This file last modified &lt;!--#flastmod file="ssi.shtml" --&gt;</code></p></div>    <p>Of course, you will need to replace the    <code>ssi.shtml</code> with the actual name of the file that    you're referring to. This can be inconvenient if you're just    looking for a generic piece of code that you can paste into any    file, so you probably want to use the    <code>LAST_MODIFIED</code> variable instead:</p><div class="example"><p><code>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -