为什么 Apache 将 .php.html 文件作为 PHP 执行? [英] Why is Apache executing .php.html files as PHP?

查看:27
本文介绍了为什么 Apache 将 .php.html 文件作为 PHP 执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题...我正在使用一个文档生成器,它会生成很多输出,如 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,而是使用

If you would prefer only the last dot-separated part of the filename to be mapped to a particular piece of meta-data, then do not use the Add* directives. For example, if you wish to have the file foo.html.cgi processed as a CGI script, but not the file bar.cgi.html, then instead of using AddHandler cgi-script .cgi, use

SetHandler cgi-script

另外,你可以谷歌搜索 apache mod_mime multiple extensions"

Also, you can google for apache mod_mime "multiple extensions"

这篇关于为什么 Apache 将 .php.html 文件作为 PHP 执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆