问题描述
我有一个奇怪的问题...我正在使用一个文档生成器,它会生成很多输出,如 docs/foo.php.html.它是 XHTML,因此在文件的开头包含 <?xml...>
标签.问题是,Apache 以某种方式决定通过 PHP 解释器运行它,即使.php"出现在文件名的中间,而不是末尾.这反过来又会触发 PHP 错误,因为它将<?
"视为开始执行 PHP 代码的命令,并立即被xml...
"弄糊涂了.代码>",跟在它后面.
I have an odd problem...I'm using a documentation generator which generates a lot of output like docs/foo.php.html. It's XHTML, and thus contains <?xml...>
tags at the beginning of file. The problem is, Apache has somehow decided to run it through the PHP interpreter, even though ".php" appears in the middle of the filename, and not at the end. This, in turn, triggers a PHP error, because it sees "<?
" as the command to start executing PHP code, and immediately gets confused by the "xml...
" which follows it.
如何将 Apache 配置为仅执行 .php 文件而不执行 .php.html 文件?字符串php.html"没有明确出现在我的 Apache 配置文件中的任何地方.有一行AddHandler php5-script .php
",但我不知道它会如何包含.php.html"文件.
How do I configure Apache to ONLY execute .php files and not .php.html files? The string "php.html" does not appear explicitly anywhere in my Apache config files. There is a line "AddHandler php5-script .php
", but I don't see how that would also include ".php.html" files.
推荐答案
问题似乎出在 mod_mime.
引自 Apache mod_mime 文档页面:
Quote from the Apache mod_mime documentation page:
如果您只想将文件名的最后一个以点分隔的部分映射到特定的元数据部分,则不要使用 Add* 指令.例如,如果您希望将文件 foo.html.cgi 处理为 CGI 脚本,而不是将文件 bar.cgi.html 处理,那么不要使用 AddHandler cgi-script .cgi,而是使用
另外,你可以谷歌搜索 apache mod_mime multiple extensions"
Also, you can google for apache mod_mime "multiple extensions"
这篇关于为什么 Apache 将 .php.html 文件作为 PHP 执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!