php htaccess 中的 AddType 导致页面下载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17024272/
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
AddType in htaccess causes page to download
提问by user1721135
I have read about 10 questions like this, but there seems to be no answer to this simple question.
我已经阅读了大约 10 个这样的问题,但是这个简单的问题似乎没有答案。
What could cause .htm files to be downloading instead of executed as php?
什么可能导致 .htm 文件被下载而不是作为 php 执行?
I am using the following code:
我正在使用以下代码:
AddType application/x-httpd-php htm
I have tried many combinations but no success.
我尝试了很多组合,但都没有成功。
What else can I try?
我还能尝试什么?
All I need is .htm and .html files to execute php.
我只需要 .htm 和 .html 文件来执行 php。
采纳答案by nick
Use AddHandler
also, change htm
to .htm
and add .html
AddHandler
也使用,更改htm
为.htm
并添加.html
AddHandler application/x-httpd-php .htm .html
AddType application/x-httpd-php .htm .html
回答by Noyeem Abdullah
I had the same issue but then i figured the version of php i'm using is php5. I changed the handler to the following and it worked!
我遇到了同样的问题,但后来我发现我使用的 php 版本是 php5。我将处理程序更改为以下内容并且它起作用了!
AddHandler x-httpd-php5-3 .php
AddHandler application/x-httpd-php5 .php
回答by Stephan
I had the same problem and couldn't find the answer here. Did find it on this cpanel forum though: https://forums.cpanel.net/threads/php-script-is-not-working-in-html-file.595195/
我遇到了同样的问题,在这里找不到答案。不过确实在这个 cpanel 论坛上找到了它:https: //forums.cpanel.net/threads/php-script-is-not-working-in-html-file.595195/
Their advice was to use this:
他们的建议是使用这个:
AddHandler application/x-httpd-ea-php56 .htm .html .shtml
AddType application/x-httpd-php5 .php
I was using PHP together with JSON though. After this PHP did work, but JSON didn't. Solved it by removing the AddType and sticking with the AddHandler
不过,我将 PHP 与 JSON 一起使用。在这个 PHP 工作之后,但 JSON 没有。通过删除 AddType 并坚持使用 AddHandler 解决了这个问题
AddHandler application/x-httpd-ea-php56 .htm .html .shtml
回答by ViorelMocanu
I'm sharing my own experience with this super frustrating issue. My host got taken over by another hosting provider and they changed technologies. One of the changes allowed me to edit my own PHP version at will, but absolutely none of them (from the lowest 5.4 to the highest 7.2) worked properly. I was using a global .htaccess across all my domains (placed in the root) and had my AddType-s and AddHangler-s at the beginning of the file. Little that I knew - when I had been changing PHP versions, the little bugger wrote the correct string defining the proper name of my PHP version at the very end of that .htaccess file. When I defined the types at the beginning of the file, I was using the wrong handle and that skipped the bottom declaration altogether, Apache didn't recognize the technology and decided to spew out a direct download.
我正在分享我自己对这个超级令人沮丧的问题的经验。我的主机被另一家托管服务提供商接管,他们改变了技术。其中一项更改允许我随意编辑自己的 PHP 版本,但绝对没有一个(从最低的 5.4 到最高的 7.2)正常工作。我在我的所有域中使用全局 .htaccess(放置在根目录中),并在文件的开头放置了我的 AddType-s 和 AddHangler-s 。我知道的很少 - 当我一直在更改 PHP 版本时,这个小家伙在 .htaccess 文件的最后写了正确的字符串来定义我的 PHP 版本的正确名称. 当我在文件开头定义类型时,我使用了错误的句柄并且完全跳过了底部声明,Apache 无法识别该技术并决定直接下载。
So watch for custom PHP handle definitions on your hosting providers.
因此,请注意您的托管服务提供商的自定义 PHP 句柄定义。
What worked for me in the end was:
最后对我有用的是:
<IfModule mime_module>
AddType application/x-httpd-ea-php72___lsphp .php .php7 .phtml .htm .html
</IfModule>
Note the "___lsphp" appended at the end of the standard "x-httpd-ea-php72" handle...
请注意附加在标准“x-httpd-ea-php72”句柄末尾的“___lsphp”...
God, that ate me up so much...
天啊,这让我吃了这么多......
回答by Sujit Pradhan
Add this line to your .htaccess file (Solved)
将此行添加到您的 .htaccess 文件(已解决)
AddHandler application/x-httpd-php5 .php .php4 .php5 .html .htm .phtml .shtml
回答by Doug D
Try: application/x-httpd-ea-php5 or application/x-httpd-ea-php56 for PHP 5.6 I had to change to this after upgrading to EasyApache 4
尝试:application/x-httpd-ea-php5 或 application/x-httpd-ea-php56 for PHP 5.6 在升级到 EasyApache 4 后我不得不改变这个
Doug Smartlab Software
道格智能实验室软件
回答by Chintan Hingrajia
add this in .htaccess file
将此添加到 .htaccess 文件中
AddType application/x-httpd-php .php .php5 .phtml
AddType 应用程序/x-httpd-php .php .php5 .phtml
回答by Christos P
Try
尝试
AddHandler fcgid-script .htm .html
Or
或者
AddHandler x-mapp-php5 .html .htm