用于解析 html 文件中的 php 的 htaccess 规则不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9369781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
htaccess rule to parse php in html files not working
提问by bsod99
can't for the life of me work out why this isn't working - on a dreamhost server, I've created an htaccess file and added AddHandler php5-cgi .html .htm
to allow php in html files, as per the dreamhost docs. On an identical dreamhost package, I've done the same thing for another site and it worked perfectly, but in this case it just won't parse the php! Is there anything I could have missed here which could be causing the problem? The htaccess is in the web root and isn't being overridden by anything else.
我一生都无法弄清楚为什么这不起作用 - 在 Dreamhost 服务器上,我创建了一个 htaccess 文件并添加AddHandler php5-cgi .html .htm
到允许 html 文件中的 php,根据 Dreamhost 文档。在一个相同的 Dreamhost 包上,我为另一个站点做了同样的事情,它运行得很好,但在这种情况下,它只是不会解析 php!有什么我可能在这里错过的可能导致问题的吗?htaccess 位于 Web 根目录中,不会被其他任何内容覆盖。
回答by Jaspreet Chahal
try this
尝试这个
AddType application/x-httpd-php .html .htm
The above setting will work if the apache is picking php as a module.
如果 apache 选择 php 作为模块,上述设置将起作用。
AddHandler application/x-httpd-php .html .htm
or
或者
AddHandler application/x-httpd-php5 .html .htm
above will work if apache is executing php as CGI?
如果 apache 将 php 作为 CGI 执行,上面会起作用吗?
there is no harm i would say to put both of the above conditions together but try one over other and see if it work for you.
我会说将上述两个条件放在一起没有什么害处,但请尝试一个,看看它是否适合您。
read more here
在这里阅读更多
回答by TerryE
Is your server using suPHP rather than mod_php or plain php-cgi?
您的服务器使用的是 suPHP 而不是 mod_php 或普通的 php-cgi?
Try using
尝试使用
AddHandler x-httpd-php .html .htm
or
或者
AddType application/x-httpd-php .html .htm
instead.
反而。
Postscript
后记
Shared Hosting services use UID based separation on individual accounts from each others. Most use suPHP, but some use suEXEC. They will use one of these. Both act as a su wrapper around php-cgi so you can't tell from the phpinfo()as its PHP scripting engine as this will report Server API
CGI/FastCGI
in both cases. For CGI initiated scripts, phpinfo doesn't report on the Apache config. You need either to look at your hosting provider's FAQ or possibly try:
共享主机服务使用基于 UID 的个人帐户相互分离。大多数使用suPHP,但有些使用suEXEC。他们将使用其中之一。两者都充当 php-cgi 的 su 包装器,因此您无法从 phpinfo() 作为其 PHP 脚本引擎中分辨出来,因为这将在两种情况下报告。对于 CGI 启动的脚本,phpinfo 不会报告 Apache 配置。您需要查看托管服务提供商的常见问题解答或可能尝试:Server API
CGI/FastCGI
<?php
header( "Content-Type: text/plain");
echo system('grep -iR LoadModule /etc/httpd /etc/apache2');
The hosting provider's support forums / FAQ might give specific configuration advice here. Have you tried them?
托管服务提供商的支持论坛/常见问题解答可能会在此处提供特定的配置建议。你试过吗?
回答by Kannika
I've got the same problem as you but I just put this AddType php .html .htm
to my .htaccess, it's working.
我和你有同样的问题,但我只是把它AddType php .html .htm
放到我的 .htaccess 中,它正在工作。
回答by Dorjan Zakja
For me it is working for only like this:
对我来说,它只适用于这样:
AddHandler php-cgi .php .htm