【发布时间】:2017-11-14 17:27:18
【问题描述】:
我正在使用 linux 服务器,并且在我的服务器中安装了 PHP 7.* 版本。我想在 HTML 文件中使用 PHP 代码。现在它在网页中呈现 PHP 代码。我在我的 .htaccess 文件中使用以下代码,但它不起作用。
AddHandler x-httpd-php .html .htm
和
AddHandler php7-script .php .html .htm
和
<FilesMatch "\.html?$">
SetHandler application/x-httpd-php7
</FilesMatch>
但所有这些都不起作用。
【问题讨论】:
-
您运行的是 Apache 还是 Nginx?如果是 Apache,请尝试:
AddType application/x-httpd-php .html .htm:stackoverflow.com/questions/4687208/… -
@Magnus 运行 Apache。当我使用 AddType application/x-httpd-php .html .htm 时,它会下载带有 html 代码的文件。
-
只有在父目录中的AllowOverride 设置为true 时才能使用.htaccess 文件。另外,您确定 php 模块已加载到 Apache 中吗?检查启用模块目录。
-
@Gordon 如果它在 OP 在 htacess 中设置 AddHandler 时尝试下载文件,那么可以安全地假设 htaccess 已加载并使用。否则,它将被简单地忽略而不做任何更改。
-
@MagnusEriksson 是的,但是如果我在 StackOverflow 学到了一件事,那么验证比假设更安全。