Smile 笑容

SHTML - SSI技术

什么是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 .shtml
AddHandler 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:决定文件大小是以字节、千字节还是兆字节为单位表示。如果以字节为单位,参数值为"bytes";对于千字节和兆字节可以使用缩写形式。同样,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.7880.com/Info/Article-2f11dda0.html

http://www.carleton.ca/~dmcfet/html/ssi.html

http://www.dizign.de/ssi/