jonvi 发表于 2017-1-1 11:39:17

Apache 支持ssi include

  ○SSI说明:SSI(Server Side Include),通常称为服务器端嵌入,是一种类似于ASP的基于服务器的网页制作技术。大多数(尤其是基于Unix平台)的WEB服务器如Netscape Enterprise Server等均支持SSI命令。主要有以下几种用用途:
     1 显示服务器端环境变量<#echo>
     2 将文本内容直接插入到文档中<#include>
     3 显示WEB文档相关信息<#flastmod #fsize> (如文件制作日期/大小等)
     4 直接执行服务器上的各种程序<#exec>(如CGI或其他可执行程序)
     5 设置SSI信息显示格式<#config>(如文件制作日期/大小显示方式) 高级SSI<XSSI>可设置变量使用if条件语句。
     <注>以上内容来源:百度百科
  ○本应用要求:在html中插入当前时间及另外一段html文本。
  ○Apache的安装和配置:SSI的应用需要安装ApacheServer,并且安装完成后需要修改其配置文件(这里以version2.2为例进行说明,默认安装路径为C:\Program Files\Apache Software Foundation\)
1 httpd.conf文件更新
・文件位置:\Apache2.2\conf\httpd.conf
・更新内容1:
     # First, we configure the "default" to be a very restrictive set of
     # features.  
     #
     <Directory />
         Options FollowSymLinks    →前加#改为注释
         AllowOverride All
         Order deny,allow             →前加#改为注释
         Deny from all                   →前加#改为注释
         Xbithack full                     →改为"Xbithack ON"
         Options Includes               →改为"Options +Includes"
     </Directory>
  ・更新内容2:
    # The Options directive is both complicated and important. Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks
    Options FollowSymLinks MultiViews Includes        →追加此行
    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None                                              →改为"AllowOverride All"
  ・更新内容3:
     #
     # "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin" should be changed to whatever your ScriptAliased
     # CGI directory exists, if you have that configured.
     #
     <Directory "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin">
         AllowOverride None        →改为"AllowOverride All"
         Options None
         Order allow,deny
         Allow from all
     </Directory>
  ・更新内容4:
    #
    # Filters allow you to process content before it is sent to the client.
    #
    # To parse .shtml files for server-side includes (SSI):
    # (You will also need to add "Includes" to the "Options" directive.)
    #
    AddType text/html .shtml
    AddType text/x-server-parsed .html        →追加此行
  2 .htaccess文件做成
・文件位置:\Apache2.2
・文件内容:
     Options +Includes
     AddOutputFilter INCLUDES .shtml
     AddHandler server-parsed html
     AddType text/x-server-parsed-html .shtml .html .htm
・做成方法:由于windows不能作成只有文件后缀没有文件名的文件,所以可以先将上面的内容作成一个txt文件,如:htaccess.txt。然后进入cmd修改其文件名。重命名语句格式为:rename htaccess.txt .htaccess
・说明:由于本应用的要求是在html中插入文本,而不是在shtml中插入,所以.htaccess文件的配置是必不可少的。
  3 重起Apache Server
  ○html做成
1 文件位置: \Apache2.2\htdocs
  2 text.html
     <head><title>SSI TEST</title></head>
     <body><form>
          <!--#include file="SSI_Insert.html"-->
          <!--#echo var="DATE_LOCAL"-->
     </form></body>
  3 SSI_Insert.html
     <div style="background-color:#FFCC33">
          <lable id="area3">AREA3</lable>
          <hr>
     </div>
  
○html的执行:
1 使用IE访问localhost
     http://127.0.0.1/text.html
  2 执行效果
     在test.html中插入了insert.html定义的背景色为#FFCC33的DIV和当前时刻
页: [1]
查看完整版本: Apache 支持ssi include