无法在 Apache 2.4 上使用 file_get_contents 执行 SSI
我正在处理一个非常遗留的项目,是在 PHP 5.4 上制作的。我们需要将其按原样转移到新服务器上,但同时将 Web 服务器从 apache 2.2 升级到 2.4 以及操作系统。 SSI 在普通 HTML 文件上工作得很好。
问题本身是一个使用 file_get_contents 回显 HTML 文件内容的核心脚本。由于某种原因,file_get_contents 可以很好地输出 HTML 文件,但它不会执行其中的 SSI。
无论如何,您知道为什么它不执行 SSI 吗?
它在 Apache 2.2 中工作正常,但在 2.4 中则不然,并且任何其他具有 SSI 的 HTML 文件都工作正常。如果我获取 HTML 文件的内容,将其保存在 html 文件中,然后继续浏览它,它执行得很好。使用 file_get_contents
回显输出时不会发生这种情况。已经尝试使用 include()
、readfile()
甚至 passthru()
以及 bash 命令来 cat
文件,但这些都不起作用。它只是打印指令本身。
我无法修改该项目,因为它太旧了并且尺寸很大,所以我无法替换文件中的SSI。
感谢您对此的关注和支持,
我尝试过什么:
- echo file_get_contents($html);
- 读取文件($html);
- 包括($html);
- passthru(“猫”。$ html);
- 从 $html 中放入 html 代码并浏览它(这有效)
我期望什么:
- 执行 SSI 的 HTML 页面
实际结果:
- 没有 SSI 的 HTML 页面(它显示
HTML 代码中的
指令)
I'm working with a very legacy project, made on PHP 5.4. We need to move it over a new server as is, but at the same time, upgrading the web server from apache 2.2 to 2.4, and the OS. SSI works fine on normal HTML files.
The problem itself is a core script that echoes the content of an HTML file using file_get_contents. For some reason, file_get_contents outputs the HTML file just fine, but it doesn't execute the SSI inside of it.
By any chance, would you know why it's not executing the SSI?
It works fine in Apache 2.2, but not in 2.4, and any other HTML files with SSI works fine. If I get the content of the HTML file, save it in an html file and then proceed browsing it, it's executed fine. It doesn't happen when echoing the output using file_get_contents
. Already tried with include()
, readfile()
, and even passthru()
with a bash command to cat
the file, but none of that works. It just prints the directives themselves.
I can't modify the project, because it's too legacy and quite big in size, so I cannot replace the SSI inside the files.
Thanks for your attention and support on this,
What have I tried:
- echo file_get_contents($html);
- readfile($html);
- include($html);
- passthru("cat " . $html);
- Putting the html code from $html and browsing it (this works)
What I expected:
- HTML page executing SSI
Actual result:
- HTML page without SSI (it shows the
<!--#include virtual="/misc-content.html"-->
directives in the HTML code)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论