将PHP代码添加到.html文件
I want to add php code to my .html file. I have searched a lot and din't find why it is not working
我想在我的.html文件中添加php代码。我经常搜索,但不知道为什么它不起作用
Steps i have followed for this:
我遵循的步骤:
1) Created a .htaccess file inside my htdocs
1)在我的htdocs中创建了一个.htaccess文件
2) And added the following things
2)并添加了以下内容
AddType text/html .shtml .shtm .htm .html
AddHandler application/x-httpd-php5.6 .html
3) Restarted my Apache.
3)重启我的Apache。
Executed my page. My page contains
执行了我的页面。我的页面包含
<?php
echo "hello";
?>
I din't see any errors and hello too. And i changed the htaccess content to
我没有看到任何错误,也打招呼。我将htaccess内容更改为
AddType application/x-httpd-php .htm .html
as mentioned here
如这里提到的
It is also not working. I don't know whether htaccess file must contain some other elements or not. Please let me know.
它也不起作用。我不知道htaccess文件是否必须包含其他一些元素。请告诉我。
Thanks
2 个解决方案
#1
1
You need to set AllowOverride
to All
in httpd.conf
, or in your virtual hosts file (httpd-vhosts.conf
) if you are using them.
如果您正在使用它们,则需要在httpd.conf中将AllowOverride设置为All,或者在虚拟主机文件(httpd-vhosts.conf)中设置。
Otherwise, directives in your .htaccess
file will not be allowed.
否则,将不允许.htaccess文件中的指令。
More information can be found here: http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride
更多信息可以在这里找到:http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride
Update
If it is set to All
, then you should be able to do either of the following.
如果将其设置为“全部”,则应该能够执行以下任一操作。
Unset the handler and reset it:
取消设置处理程序并重置它:
RemoveHandler .html .htm
AddType application/x-httpd-php .html .htm
Or, use FilesMatch
:
或者,使用FilesMatch:
<FilesMatch "\.(htm|html|php)$">
SetHandler application/x-httpd-php
</FilesMatch>
更多相关文章
- 加载跨域的HTML页面AJAX
- 性能权衡 - CSS效率,CSS文件大小,HTML文件大小
- 上传文件,那么form中用来接收文件的数据成员是什么类型?
- 请问json文件在html head中以script的形式导入了,怎样读取这个jso
- HTML5,简单的注册页面
- 帮助相对路径链接到本地文件
- html文件上传到vss上面后文件大小改变
- 在页面重新加载时添加活动链接和jquery幻灯片切换到自定义ajax w
- asp.net core,返回一个view,并没有正确的返回html,而是view文件原