服务器未将 .html 解析为 PHP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6295141/
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
Server not parsing .html as PHP
提问by Ben G
I have the included code in my .htaccess file but the php code I am attempting to include is not working.
我的 .htaccess 文件中有包含的代码,但我尝试包含的 php 代码不起作用。
Options +Includes
AddType text/html .htm .html
AddHandler server-parsed .htm .html
AddType application/octet-stream .vcf
AddOutputFilterByType DEFLATE text/html text/htm text/plain text/css text/php text/javascript application/x-javascript
回答by John Conde
Try:
尝试:
AddType application/x-httpd-php .html .htm
UPDATE 1
更新 1
It may be PHP version specific. If you're using PHP5 try:
它可能是特定于 PHP 版本的。如果您使用的是 PHP5,请尝试:
AddType application/x-httpd-php5 .html .htm
UPDATE 2
更新 2
Try:
尝试:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
Or here's yet another alternative way to do this:
或者这里还有另一种方法来做到这一点:
<FilesMatch "\.html$">
ForceType application/x-httpd-php
</FilesMatch>
回答by Gjaa
On Apache 2.2.22 (Ubuntu) with Php 5 add these lines to /etc/apache2/mods-enabled/php5.conf
在带有 PHP 5 的 Apache 2.2.22 (Ubuntu) 上,将这些行添加到 /etc/apache2/mods-enabled/php5.conf
<FilesMatch ".+\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
and restart apache
并重新启动apache
sudo service apache2 restart
回答by CatsDontWearPants
For godaddy shared hosting (php-cgi):
对于godaddy 共享主机(php-cgi):
From http://sagarnangare.com/parse-html-as-php-using-htaccess-file-on-godaddy/
来自http://sagarnangare.com/parse-html-as-php-using-htaccess-file-on-godaddy/
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
That's the only one that worked for me.
这是唯一对我有用的方法。
回答by Hayden
If you are using Plesk Control Panel:
如果您使用的是 Plesk 控制面板:
PHP is running as an Apache module:
PHP 作为 Apache 模块运行:
<IfModule mod_php5.c>
AddHandler php5-script .php .html .htm
AddType text/html .php .html .htm
</IfModule>
PHP is running as a FastCGI application:
PHP 作为 FastCGI 应用程序运行:
<IfModule mod_fcgid.c>
<Files ~ (\.html)>
SetHandler fcgid-script
FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .html
Options +ExecCGI
allow from all
</Files>
</IfModule>
PHP is running as a CGI application:
PHP 作为 CGI 应用程序运行:
<Files ~ (\.html)>
SetHandler None
AddHandler php-script .html
Options +ExecCGI
allow from all
</Files>
Then /usr/local/psa/admin/sbin/httpdmng --reconfigure-all
然后 /usr/local/psa/admin/sbin/httpdmng --reconfigure-all
回答by Adrian
VERY IMPORTANT that you must replace the "php5" to your OWN exact PHP version in the:
非常重要的是,您必须将“php5”替换为您自己的确切 PHP 版本:
AddHandler application/x-httpd-php5 .html .htm
AddType application/x-httpd-php5 .html .htm
Because I have tried everithing in every way from all over the web, but nothing worked until I found a "MultiPHP Manager" menupoint under my CPanel, and under this I found out that my exact PHP version/name/id (or whatever it is called) was "ea-php56", so my working code is:
因为我已经从整个网络上以各种方式尝试了everithing,但是直到我在我的 CPanel 下找到一个“MultiPHP Manager”菜单点之前都没有任何效果,在此之下我发现我的确切 PHP 版本/名称/ID(或任何它是调用)是“ea-php56”,所以我的工作代码是:
AddHandler application/x-httpd-ea-php56 .html .htm
AddType application/x-httpd-ea-php56 .html .htm
I have browsed all day the forums, comments, but I haven't found this very important information anywhere, so maybe You also have to look up your exact PHP version if it is not working!
我已经浏览了一整天的论坛,评论,但我没有在任何地方找到这个非常重要的信息,所以如果它不起作用,也许您还必须查找确切的 PHP 版本!
回答by Masetti
If your server is using PHP5 then use this:
如果您的服务器使用 PHP5,请使用以下命令:
AddHandler application/x-httpd-php5 .html .htm
If it's not PHP5 then use
如果不是 PHP5 则使用
AddHandler application/x-httpd-php .html .htm
It worked for me on CPanel hosting.
它在 CPanel 托管上对我有用。
If you are using some other linux hosting try this:
如果您使用的是其他 linux 主机,请尝试以下操作:
<IfModule mod_mime.c>
AddType application/x-httpd-php .html .php .htm
</IfModule>
Options +FollowSymlinks
回答by PlanetHackers
For Godaddy server it worked for me
对于 Godaddy 服务器,它对我有用
Options +ExecCGI
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
回答by dan_nl
BenG, did any solution ever work for you?
BenG,有没有对你有用的解决方案?
this may help -- i found this topic confusing, because either statement worked for me in my local dev environment
这可能会有所帮助——我发现这个话题令人困惑,因为这两种说法在我的本地开发环境中都对我有用
AddHandler application/x-httpd-php .html .htm
or
AddType application/x-httpd-php .html .htm
after reading the apache documentation on both directives, it seems that you want to use AddTypewhen adding a mime type not yet handled by apache, and AddHandlerwhen you want apache to handle a file differently than its default handling of that file type. i may be wrong, but that does seem to be what the manual is saying.
在阅读了关于这两个指令的 apache 文档后,似乎您想在添加 apache 尚未处理的 mime 类型时使用AddType,而在您希望 apache 以不同于其默认处理该文件类型的方式处理文件时使用AddHandler。我可能是错的,但这似乎是手册所说的。
so if you want apache to handle .html and .htm as if they were .php files then you would use the directive :
因此,如果您希望 apache 处理 .html 和 .htm 就好像它们是 .php 文件一样,那么您将使用以下指令:
AddHandler application/x-httpd-php .html .htm
the .htaccess file you mention above is doing a few things, so maybe you could first verify that it does indeed tell apache to handle .htm and .html files as if they are .php files; then move on to the other directives you want to use.
您上面提到的 .htaccess 文件正在做一些事情,所以也许您可以先验证它确实告诉 apache 处理 .htm 和 .html 文件,就好像它们是 .php 文件一样;然后转到您要使用的其他指令。
回答by Sergey
Don't know if it helps but... My example after hour of searching:
不知道它是否有帮助,但是......经过一个小时的搜索后我的例子:
AddType application/x-httpd-php .php
LoadModule php5_module "c:/server/php5/php5apache2_2.dll"
ScriptAlias /_php/ "c:/server/php5/"
in httpd.conf
在 httpd.conf 中
Without LoadModule and ScriptAlias it didn't process php at all and showed plaintext
没有 LoadModule 和 ScriptAlias,它根本不处理 php 并显示纯文本
回答by Kannika
You can just try to put only this AddType php .html .htm
to your htaccess, If this AddType application/x-httpd-php .html .htm
doesn't work.
您可以尝试仅将其放入AddType php .html .htm
您的 htaccess,如果这AddType application/x-httpd-php .html .htm
不起作用。