首页 > web优化 > Apache配置支持SHTML

Apache配置支持SHTML

2009年10月24日 李悦 发表评论 阅读评论

一、前言
CMS中模板用置标嵌套头尾模板的方法,方便快捷,但是存在弊端,当文档数据量庞大时,只要嵌套的头尾模板稍有改动,就得完全发布站点才能更新所有的文档模板。数据量有几十万条,这个就是噩梦。使用SSI技术,将头尾作为独立文件嵌入到页面中,只要更新发布头尾文件就可以了。

二、Apache配置
Apache默认是不支持SSI的,更改httpd.conf来进行配置。
搜索“AddType text/html .shtml”,找到下面两行:

# AddType text/html .shtml
# AddOutputFilter INCLUDES .shtml

将这两行前面的#注释去掉。
搜索下面的默认页配置:

DirectoryIndex index.html index.htm

将index.shtml放到第一个位置

DirectoryIndex index.shtml index.html index.htm

接下来修改虚拟主机配置来支持shtml
例如下面的虚拟主机配置:

<VirtualHost *:80>
ServerAdmin webmaster@cas.cn
<Directory "/var/web/casweb/cas">
Options -Indexes FollowSymLinks Includes
Order allow,deny
Allow from all
</Directory>
DocumentRoot /var/web/casweb/cas/
ServerName www.cas.cn
ErrorLog logs/www.cas.cn-error_log
TransferLog "|/usr/local/sbin/cronolog /usr/local/apache2/logs/www.cas.cn-%Y%m%d-access_log"
</VirtualHost>

蓝色的Includes是在原来的基础上增加的。

三、SSI页面调用方法

用法:

<!--#include virtual="index.shtml" -->

include路径不能跨域,只能使用相对路径。
将上述代码插入到模板代码中,并将模板扩展名改为shtml
链接的文件名可以使用置标来获取,但必须指定具体的文件名,如index.shtml

分类: web优化 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.