AddType application/x-httpd-php .php 不呈现 PHP

Lap*_*pys 6 php apache

添加此代码:

AddType application/x-httpd-php .php

...
#AddEncoding x-compress .Z
#AddEncoding x-gzip .gz .tgz
#
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
Run Code Online (Sandbox Code Playgroud)

C:\Apache24\bin\httpd.conf 下载我的系统上的所有PHP页面,而不是渲染。

在此之前,PHP 页面被解析为原始文本。

需要帮助!

Luc*_*cas 6

有两个问题:

  1. application/x-httpd-php不是 MIME 类型,而是处理程序。这意味着您的指令必须是AddHandler而不是AddType

  2. application/x-httpd-php不是有效的处理程序。处理程序必须在字符串末尾包含 PHP 版本数字

总而言之,假设 PHP 7.2 版,你想要的是

   ? AddHandler application/x-httpd-php72 .php代替
    AddType application/x-httpd-php .php

  • 这确实应该是公认的答案...在托管公司将网站自动升级到 PHP 7 后,这为我修复了一些旧页面。谢谢,卢卡斯。 (2认同)