SSI技術—SHTML的解釋(產生靜態時用的最火)_應用技巧

來源:互聯網
上載者:User
什麼是shtml SHTML文法 SHTML教程 格式 編寫 技術
使用SSI (Server Side Include)技術
想要找到既富有創意的平面設計人員,又有指令碼開發經驗的人員,實在是太難了。而如果一個百分之百的頁面都是php指令碼的網站,將為頁面維護帶來非常大的困難。而且使用了php的自動加頭和加尾的方法,使得幾乎所有頁面都是語義不完整的,不能藉助任何一款頁面設計工具工作,是另一個弊病。
利用SSI技術,可以有效將HTML網頁和CGI指令碼邏輯上分開,也可以將重複的HTML元素抽象和獨立出來,減輕維護負擔。
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.
全文: 
配置Apache,支援SSI# This tells Apache that you want to permit files to# be parsed for SSI directives.Options +Includes
# At Linux or unix can use#  Options +Includes -IncludesNOEXEC# win32 not use it
# You have to tell Apache which files should be parsed.AddType text/html .shtmlAddHandler server-parsed .shtml
SSI文法
Basic SSI directives Syntax
<!--#element attribute=value attribute=value ... -->
Today's date
<!--#config timefmt="%Y/%m/%d %a %H:%M:%S" -->Today is <!--#echo var="DATE_LOCAL" -->
Modification date of the file
This document last modified <!--#flastmod file="index.html" -->
Including the results of a CGI program
<!--#include virtual="/cgi-bin/counter.pl" --><!--#include virtual="/cgi-bin/example.cgi?argument=value" -->
You can use "#exec cgi=" directive, but it can be disabled using the IncludesNOEXEC Option.
Including a standard footer
<!--#include virtual="/footer.html" -->
Executing commands
<!--#exec cmd="ls" -->
This feature is dangerous. You can allow SSI, but not the exec feature, with the IncludesNOEXEC argument to the Options directive.
Setting variables
<!--#set var="modified" value="$LAST_MODIFIED" --><!--#set var="date" value="${DATE_LOCAL}_${DATE_GMT}" -->
Conditional expressions
<!--#if expr="test_condition" --><!--#elif expr="test_condition" --><!--#else --><!--#endif -->
1、Config命令 
  Config命令主要用於修改SSI的預設設定。其中: 
  Errmsg:設定預設錯誤資訊。為了能夠正常的返回使用者設定的錯誤資訊,在HTML檔案中Errmsg參數必須被放置在其它SSI命令的前面,否則用戶端只能顯示預設的錯誤資訊,而不是由使用者設定的自訂資訊。 
    <!--#config errmsg="Error! Please email webmaster@mydomain.com -->  
  Timefmt:定義日期和時間的使用格式。Timefmt參數必須在echo命令之前使用。 
    <!--#config timefmt="%A, %B %d, %Y"-->
    <!--#echo var="LAST_MODIFIED" --> 
  顯示結果為: 
    Wednesday, April 12, 2000  
  也許使用者對上例中所使用的%A %B %d感到很陌生,下面我們就以表格的形式總結一下SSI中較為常用的一些日期和時間格式。 www.domain.com
  Sizefmt:決定檔案大小是以位元組、KB還是MB為單位表示。如果以位元組為單位,參數值為"bytes";對於KB和MB可以使用縮寫形式。同樣,sizefmt參數必須放在fsize命令的前面才能使用。 
    <!--#config sizefmt="bytes" -->
    <!--#fsize file="index.html" -->  
  2、Include命令 
  Include命令可以把其它文檔中的文字或圖片插入到當前被解析的文檔中,這是整個SSI的關鍵所在。通過Include命令只需要改動一個檔案就可以瞬間更新整個網站! 
  Include命令具有兩個不同的參數: 
  Virtual:給出到伺服器端某個文檔的虛擬路徑。例如: 
    <!--#include virtual="/includes/header.html" -->  
  File:給出到目前的目錄的相對路徑,其中不能使用"../",也不能使用絕對路徑。例如: 
    <!--#include file="header.html" --> 
  這就要求每一個目錄中都包含一個header.html檔案。 
  3、Echo命令 
  Echo命令可以顯示以下各環境變數:
  DOCUMENT_NAME:顯示當前文檔的名稱。
    <!--#echo var="DOCUMENT_NAME" --> 
顯示結果為:
    index.html
  DOCUMENT_URI:顯示當前文檔的虛擬路徑。例如:
    <!--#echo var="DOCUMENT_URI" --> 
  顯示結果為: 
    /YourDirectory/YourFilename.html  
  隨著網站的不斷髮展,那些越來越長的URL地址肯定會讓人頭疼。如果使用SSI,一切就會迎刃而解。
另外一個關於apache中ssi技術的教程可以查閱:
Apache指南:伺服器端包含入門
http://www.kreny.com/doc/apache2.0/howto/ssi.html
參考網頁
http://www.worldhello.net/doc/website_howto/ssi.html
http://www.carleton.ca/~dmcfet/html/ssi.html 
http://www.dizign.de/ssi/ 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.