在.shtml文件常用#include指令引入html文件,而使用#include指令必须在服务器开启ssi服务,在Windows操作系统下的Apache服务器中开启 SSI功能主要通过修改Apache的配置文件httpd.conf。
1、启用mod_include模块
在Apache的安装目录下,找到conf/httpd.conf文件并编辑,搜索找到下面内容:
LoadModule include_module modules/mod_include.so
确保它前面没有注释符号#,如果有就删除。
2、修改目录配置以允许SSI服务
在文件中搜索:
Options Indexes FollowSymLinks
找到:
<Directory "${SRVROOT}/htdocs">
Options Indexes FollowSymLinks
</Directory>注意:Directory是网站的访问目录。
在这行的末尾添加Includes,修改为:
<Directory "${SRVROOT}/htdocs">
Options Indexes FollowSymLinks Includes
</Directory>3、指定 SSI 文件的扩展名
在文件中搜索找到以下两行,去掉它们开头的#注释符号:
AddType text/html .shtml AddOutputFilter INCLUDES .shtml
注意:如果想让Apache也解析普通.html文件中的SSI指令,可以将第二行修改为AddOutputFilter INCLUDES .html。但出于性能考虑,通常建议仅对特定的.shtml文件启用解析。
4、重启 Apache 服务
保存对httpd.conf文件的修改,然后重启Apache服务器让配置生效。
进入D:\Server\Apache24\bin目录执行重启Apache服务器的命令:
./httpd.exe -k restart
提醒:进入自己服务器Apache的实际安装路径。