服务器没有将.html解析为PHP

Ben*_*n G 18 php apache .htaccess

我在.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
Run Code Online (Sandbox Code Playgroud)

Joh*_*nde 31

尝试:

AddType application/x-httpd-php .html .htm
Run Code Online (Sandbox Code Playgroud)

更新1

它可能是PHP版本特定的.如果您使用的是PHP5,请尝试:

AddType application/x-httpd-php5 .html .htm
Run Code Online (Sandbox Code Playgroud)

更新2

尝试:

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
Run Code Online (Sandbox Code Playgroud)

或者这是另一种替代方法:

<FilesMatch "\.html$">
    ForceType application/x-httpd-php
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)


Gja*_*jaa 18

在Apache 2.2.22(Ubuntu)上使用Php 5添加这些行 /etc/apache2/mods-enabled/php5.conf

<FilesMatch ".+\.html$">
    SetHandler application/x-httpd-php
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)

并重新启动apache

sudo service apache2 restart
Run Code Online (Sandbox Code Playgroud)


小智 8

对于godaddy共享主机(php-cgi):

来自http://sagarnangare.com/parse-html-as-php-using-htaccess-file-on-godaddy/

AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
Run Code Online (Sandbox Code Playgroud)

这是唯一一个适合我的人.


小智 6

如果您使用的是Plesk控制面板:

PHP作为Apache模块运行:

<IfModule mod_php5.c>
   AddHandler php5-script .php .html .htm
   AddType text/html .php .html .htm
</IfModule>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

PHP作为CGI应用程序运行:

<Files ~ (\.html)>
    SetHandler None
    AddHandler php-script .html
    Options +ExecCGI
    allow from all
</Files>
Run Code Online (Sandbox Code Playgroud)

然后是/ usr/local/psa/admin/sbin/httpdmng --reconfigure-all

http://kb.odin.com/en/115773


小智 5

非常重要的是,您必须将“php5”替换为您自己的确切 PHP 版本:

AddHandler application/x-httpd-php5 .html .htm

AddType application/x-httpd-php5 .html .htm
Run Code Online (Sandbox Code Playgroud)

因为我已经从网络上以各种方式尝试了everithing,但是直到我在我的 CPanel 下找到一个“MultiPHP Manager”菜单点之前都没有任何效果,在此之下我发现我的确切 PHP 版本/名称/ID(或任何它是调用)是“ea-php56”,所以我的工作代码是:

AddHandler application/x-httpd-ea-php56 .html .htm

AddType application/x-httpd-ea-php56 .html .htm
Run Code Online (Sandbox Code Playgroud)

我已经浏览了一整天的论坛,评论,但我没有在任何地方找到这个非常重要的信息,所以如果它不起作用,也许您还必须查找确切的 PHP 版本!