xampp中启用ssi需两步:先取消httpd.conf中#loadmodule include_module modules/mod_include.so的注释并重启;再在对应块中添加options +includes、addtype text/html .shtml和addoutputfilter includes .shtml,文件须用.shtml后缀且路径符合file(相对当前目录)或virtual(相对于根目录)规则。

XAMPP 默认不启用 Apache 的 SSI(Server Side Includes)功能,即使你写了 <!--#include file="header.html" -->,浏览器也会原样显示注释,或者返回 500 错误。根本原因就两点:模块没加载、文件类型没注册。
确认 mod_include 模块已启用
Windows 下 XAMPP 的 mod_include.so 默认是编译好的,但被注释掉了。必须手动启用:
- 打开
\xampp\apache\conf\httpd.conf - 搜索
include_module,找到这行:#LoadModule include_module modules/mod_include.so - 删掉开头的
#取消注释 - 保存后重启 Apache(在 XAMPP 控制面板里 Stop 再 Start)
验证是否生效:命令行运行 xampp\apache\bin\httpd.exe -M | findstr include,输出含 include_module 即成功。
让 .shtml 文件触发 SSI 解析
Apache 不会自动对 .html 或 .php 执行 SSI —— 这是安全设计。推荐用 .shtml 作为 SSI 专用后缀,避免全站解析开销:
- 在
httpd.conf的<directory></directory>区块内,确保有这三行:
Options +Includes AddType text/html .shtml AddOutputFilter INCLUDES .shtml
注意:Options +Includes 必须和 AddOutputFilter 同作用域(比如都在同一个 <directory></directory> 里),否则无效。
Apache Superset 是一个广泛采用的开源 BI 平台,用于 SQL 探索、图表构建和仪表板交付。当代理需要查询仓库数据、组装仪表板或使用成熟的分析界面解释指标而不是临时笔记本代码时,此技能非常有用。
改完重启 Apache,把测试文件命名为 test.shtml,再访问 http://localhost/test.shtml 才会执行包含逻辑。
file 和 virtual 路径写法不能混用
SSI 的 file 和 virtual 参数路径规则完全不同,写错直接 500:
-
<!--#include file="nav.shtml" -->:只认**当前文件所在目录的相对路径**,不支持../,也不能以/开头 -
<!--#include virtual="/includes/footer.shtml" -->:路径是**相对于网站根目录(DocumentRoot)**,必须以/开头,且目标文件必须能被 Web 直接访问(比如放在\xampp\htdocs\includes\下)
常见坑:file="../header.html" 在 XAMPP 下必报错;virtual="footer.shtml"(缺开头 /)会静默失败或 500。路径权限也要检查:被包含文件需是 644,且 SELinux(若启用)不能阻止 Apache 读取。
调试时优先看 Apache 错误日志
SSI 失败很少给友好提示,浏览器可能只显示空白或原始注释。真正线索在日志里:
- 日志路径:
\xampp\apache\logs\error.log - 典型错误:
unable to include "xxx" in parsed file(file路径越界)、File does not exist(virtual路径不对或文件不可达) - 如果页面完全不渲染,检查响应头是否为
text/html—— 若是application/octet-stream,说明AddType没生效
最易忽略的是:XAMPP 的 httpd.conf 里可能有多处 <directory></directory> 块(比如还套了 httpd-xampp.conf),Options +Includes 必须写在最终生效的那个块里,而不是只改主配置顶部。










