gpt4 book ai didi

php - 将 php 代码添加到 .html 文件

转载 作者:可可西里 更新时间:2023-10-31 23:39:45 26 4
gpt4 key购买 nike

我想将 php 代码添加到我的 .html 文件中。我已经搜索了很多,但没有找到它不起作用的原因

我为此遵循的步骤:

1) 在我的 htdocs 中创建了一个 .htaccess 文件

2) 并添加了以下内容

  AddType text/html .shtml .shtm .htm .html
AddHandler application/x-httpd-php5.6 .html

3) 重新启动我的 Apache。

执行我的页面。我的页面包含

<?php
echo "hello";
?>

我没有看到任何错误,你好。我将 htaccess 内容更改为

AddType application/x-httpd-php .htm .html

如前所述here

它也不起作用。我不知道 htaccess 文件是否必须包含其他一些元素。请告诉我。

谢谢

最佳答案

您需要在 httpd.conf 或您的虚拟主机文件 (httpd-vhosts.conf) 中将 AllowOverride 设置为 All。 conf) 如果你正在使用它们。

否则,您的.htaccess 文件中的指令将不被允许。

可在此处找到更多信息:http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride

更新

如果它设置为 All,那么您应该能够执行以下任一操作。

取消设置处理程序并重置它:

RemoveHandler .html .htm 
AddType application/x-httpd-php .html .htm

或者,使用 FilesMatch:

<FilesMatch "\.(htm|html|php)$">
SetHandler application/x-httpd-php
</FilesMatch>

关于php - 将 php 代码添加到 .html 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29893513/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com