【问题标题】:parse html as php with htaccess prompts to downloading使用 htaccess 提示将 html 解析为 php 以进行下载
【发布时间】:2015-09-22 12:35:36
【问题描述】:

我有一个 html 网站,我希望将 html 页面解析为 php;我为此使用了一个 htaccess 文件。

在在线服务器上,它可以正常工作。命令是:

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

但是,在 localhost 服务器上它根本不起作用。当我访问该页面时,它会提示下载文件而不是显示该页面。

我猜我正在使用 PHP 5.6.3 和 PHP 作为模块。

我在 htaccess 中尝试过各种类似的命令,比如:

  • AddType application/x-httpd-php .html .htm
  • AddType application/x-httpd-php5 .html .htm
  • AddHandler application/x-httpd-php .html .htm
  • AddHandler application/x-httpd-php5 .html .htm
  • AddHandler application/x-httpd-php .html .htm
  • AddHandler application/x-httpd-php5 .html .htm
  • AddHandler x-mapp-php .html .htm
  • AddHandler x-mapp-php5 .html .htm

但没有运气。

我也尝试了RemoveHandler .html .htm,但没有成功。

我检查了 httpd.conf 文件,其中有以下内容:

LoadModule php5_module "C:/Program Files/PHP/php5apache2_4.dll"

AllowOverride All

<Directory "D:/mysites/">
    AllowOverride All
    Require all granted
</Directory>

那我应该去哪里找问题呢..?

任何提示表示赞赏。

【问题讨论】:

  • 如果你下载文件,下载的文件是否经过PHP处理?正在发送什么 Content-Type 标头? (我的赌注是您列表中的第一个 AddType。)

标签: php apache .htaccess


【解决方案1】:

你应该试试这样的:

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

但最好将其添加到您的虚拟主机中,或者如果可能的话,将其添加到您的 apache2.conf 中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-04
    • 2011-11-03
    • 1970-01-01
    相关资源
    最近更新 更多