XAMPP 默认已编译但禁用 mod_include 模块,需在 httpd.conf 中取消 LoadModule include_module modules/mod_include.so 的注释并重启 Apache;同时须在 <Directory> 块中配置 Options +Includes、AddType text/html .shtml 和 AddOutputFilter INCLUDES .shtml 才能使 .shtml 文件解析 SSI 指令。

确认 XAMPP 自带的 mod_include 是否已启用
XAMPP 默认已编译 mod_include,但通常处于禁用状态。直接访问含 <!--#include file="header.html" --> 的页面却看到原样注释或 500 错误,第一反应就是模块没开。
检查方式:打开 XAMPP 控制面板 → 点击 Apache 行右侧的 Config → 选择 httpd.conf → 搜索 mod_include。确认这一行未被注释:
LoadModule include_module modules/mod_include.so
若前面有 #,删掉;保存后重启 Apache。
让 .shtml 文件可执行 SSI 指令
XAMPP 不会自动对任何后缀启用 SSI,哪怕模块开着。必须显式告诉 Apache:遇到 .shtml 就走 INCLUDES 过滤器。
仍在 httpd.conf 中,找到 <Directory ""${SRVROOT}/htdocs"> 区块,在其内部添加三行:
Apache Superset 是一个广泛采用的开源 BI 平台,用于 SQL 探索、图表构建和仪表板交付。当代理需要查询仓库数据、组装仪表板或使用成熟的分析界面解释指标而不是临时笔记本代码时,此技能非常有用。
Options +Includes AddType text/html .shtml AddOutputFilter INCLUDES .shtml
-
Options +Includes是硬性要求,缺了就拒绝解析 SSI -
AddType确保浏览器收到text/html响应头,否则可能触发下载 -
AddOutputFilter是实际触发解析的关键,不能漏
改完保存,重启 Apache。此时访问 test.shtml 才会真正执行 <!--#include -->。
file 和 virtual 路径写法不能混用
SSI 的 file 和 virtual 参数行为完全不同,写错不会报错提示,而是静默失败或 500。
-
<!--#include file="nav.html" -->:路径相对于当前文件所在目录,不支持../向上跳转 -
<!--#include virtual="/includes/footer.shtml" -->:路径相对于网站根目录(即htdocs),必须以/开头,且目标文件需在 DocumentRoot 内可被 Web 访问
举例:你的页面是 htdocs/blog/post.shtml,想包含同级的 nav.shtml,必须写 file="nav.shtml";想包含 htdocs/includes/ads.html,必须写 virtual="/includes/ads.html"。
Windows 下 SELinux 不是问题,但文件权限和扩展名要盯紧
XAMPP 运行在 Windows 上,不用操心 SELinux 或 Linux 权限模型,但有两个隐形坑:
- Apache 默认不解析
.html的 SSI —— 即使你加了AddOutputFilter INCLUDES .html,也容易因 MIME 类型冲突或缓存导致失效。坚持用.shtml最省事 - Windows 文件系统不区分大小写,但 Apache 配置和路径中大小写仍需一致。比如配置了
AddOutputFilter INCLUDES .shtml,但文件实际叫HEADER.SHTML,在某些 XAMPP 版本中可能不触发解析 - 确保被包含文件本身可读(右键属性 → 安全标签页里,Users 组至少有“读取”权限)
调试时最有效的办法是看 Apache 错误日志(XAMPP 控制面板 → Logs → error.log),500 错误几乎都带具体原因,比如 unable to include "xxx" in parsed file 就是 file 路径越界了。

















