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

📄 ssi.html.en

📁 apache 安装教程 apache 安装教程
💻 EN
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">  <head>    <meta name="generator" content="HTML Tidy, see www.w3.org" />    <title>Apache Tutorial: Introduction to Server Side    Includes</title>  </head>  <!-- Background white, links blue (unvisited), navy (visited), red (active) -->  <body bgcolor="#FFFFFF" text="#000000" link="#0000FF"  vlink="#000080" alink="#FF0000">        <div align="CENTER">      <img src="../images/sub.gif" alt="[APACHE DOCUMENTATION]" />      <h3>Apache HTTP Server Version 1.3</h3>        <p><small><em>Is this the version you want?  For more recent         versions, check our <a href="/docs/">documentation          index</a>.</em></small></p>    </div>    <h1 align="CENTER">Apache Tutorial: Introduction to Server Side    Includes</h1>    <a id="__index__" name="__index__"></a> <!-- INDEX BEGIN -->         <ul>      <li><a      href="#apachetutorial:introductiontoserversideincludes">Apache      Tutorial: Introduction to Server Side Includes</a></li>      <li><a href="#whataressi">What are SSI?</a></li>      <li><a href="#configuringyourservertopermitssi">Configuring      your server to permit SSI</a></li>      <li>        <a href="#basicssidirectives">Basic SSI directives</a>         <ul>          <li><a href="#today'sdate">Today's date</a></li>          <li><a href="#modificationdateofthefile">Modification          date of the file</a></li>          <li><a href="#includingtheresultsofacgiprogram">Including          the results of a CGI program</a></li>        </ul>      </li>      <li>        <a href="#additionalexamples">Additional examples</a>         <ul>          <li><a href="#whenwasthisdocumentmodified">When was this          document modified?</a></li>          <li><a href="#includingastandardfooter">Including a          standard footer</a></li>          <li><a href="#whatelsecaniconfig">What else can I          config?</a></li>          <li><a href="#executingcommands">Executing          commands</a></li>        </ul>      </li>      <li>        <a href="#advancedssitechniques">Advanced SSI        techniques</a>         <ul>          <li><a href="#settingvariables">Setting          variables</a></li>          <li><a href="#conditionalexpressions">Conditional          expressions</a></li>        </ul>      </li>      <li><a href="#conclusion">Conclusion</a></li>    </ul>    <!-- INDEX END -->    <hr />    <h2><a id="apachetutorial:introductiontoserversideincludes"    name="apachetutorial:introductiontoserversideincludes">Apache    Tutorial: Introduction to Server Side Includes</a></h2>    <table border="1">      <tr>        <td valign="top"><strong>Related Modules</strong><br />         <br />         <a href="../mod/mod_include.html">mod_include</a><br />         <a href="../mod/mod_cgi.html">mod_cgi</a><br />         <a href="../mod/mod_expires.html">mod_expires</a><br />         </td>        <td valign="top"><strong>Related Directives</strong><br />         <br />         <a href="../mod/core.html#options">Options</a><br />         <a        href="../mod/mod_include.html#xbithack">XBitHack</a><br />         <a href="../mod/mod_mime.html#addtype">AddType</a><br />         <a        href="../mod/mod_mime.html#addhandler">AddHandler</a><br />         <a        href="../mod/mod_setenvif.html#browsermatchnocase">BrowserMatchNoCase</a><br />         </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>    <hr />    <h2><a id="whataressi" name="whataressi">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>    <hr />    <h2><a id="configuringyourservertopermitssi"    name="configuringyourservertopermitssi">Configuring your server    to permit SSI</a></h2>    <p>To permit SSI on your server, you must have <a    href="../mod/mod_include.html">mod_include</a> installed and    enabled. Additionally, you must have the following    directive either in your <code>httpd.conf</code> file, or in a    <code>.htaccess</code> file:</p><pre>        Options +Includes</pre>    <p>This tells Apache that you want to permit files to be parsed    for SSI directives.  Note that most configurations contain     multiple <a href="../mod/core.html#options">Options</a> 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><pre>        AddType text/html .shtml        AddHandler server-parsed .shtml</pre>    <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>XBitHack</code>    directive:</p><pre>        XBitHack on</pre>    <p><code>XBitHack</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><pre>        chmod +x pagename.html</pre>    <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>XBitHack</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 <a      href="../mod/mod_expires.html">mod_expires</a> to set an      explicit expiration time on your files, thereby letting      browsers and proxies know that it is acceptable to cache      them.</li>    </ol>    <hr />    <h2><a id="basicssidirectives" name="basicssidirectives">Basic    SSI directives</a></h2>    <p>SSI directives have the following syntax:</p><pre>        &lt;!--#element attribute=value attribute=value ... --&gt;</pre>    <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 id="today'sdate" name="today'sdate">Today's    date</a></h3><pre>        &lt;!--#echo var="DATE_LOCAL" --&gt;</pre>    <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><pre>        &lt;!--#config timefmt="%A %B %d, %Y" --&gt;        Today is &lt;!--#echo var="DATE_LOCAL" --&gt;</pre>    <h3><a id="modificationdateofthefile"    name="modificationdateofthefile">Modification date of the    file</a></h3><pre>        This document last modified &lt;!--#flastmod file="index.html" --&gt;</pre>    <p>This element is also subject to <code>timefmt</code> format    configurations.</p>

⌨️ 快捷键说明

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