让静态页面也支持 include
在做网站的时候,如果要将重复的页面部分抽出来,然后include到其他页面,之前只知道在JSP,PHP等动态语言中可以用include这个方法做到,今天学了一招,在纯html页面中也是可以的。
不过别高兴早了,你的HTML页面得放在Apache服务器下面,因为这个方法用到了Apache的SSI(Server Side Includes)功能,具体介绍可以查看这里。
大体配置方法如下:
- 在apache的配置文件http.conf中找到
- 在http.conf中找到
- 重启Apache服务器
- 在一个页面中include另一个页面,例如在page1.html中include page2.html 的内容:
Options FollowSymLinks
更改为:
Options FollowSymLinks Includes
AddType text/html .shtml AddOutputFilter INCLUDES .shtml
添加你要支持的后缀,比如我们常用的.html:
AddType text/html .shtml AddOutputFilter INCLUDES .shtml AddOutputFilter INCLUDES .html
<!--#include virtual="page2.html"-->
Tags: apache

