AddType in htaccess causes page to download


AddType in htaccess causes page to download

I have read about 10 questions like this, but there seems to be no answer to this simple question.
What could cause .htm files to be downloading instead of executed as 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.


Solution 1:

Use AddHandler also, change htm to .htm and add .html

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

Solution 2:

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!

AddHandler x-httpd-php5-3 .php
AddHandler application/x-httpd-php5 .php

Solution 3:

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.

So watch for custom PHP handle definitions on your hosting providers.

What worked for me in the end was:

<IfModule mime_module>
  AddType application/x-httpd-ea-php72___lsphp .php .php7 .phtml .htm .html

Note the “___lsphp” appended at the end of the standard “x-httpd-ea-php72” handle…

God, that ate me up so much…

Solution 4:

Add this line to your .htaccess file (Solved)

AddHandler application/x-httpd-php5 .php .php4 .php5 .html .htm .phtml .shtml

Solution 5:

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

Smartlab Software

Solution 6:

I had the same problem and couldn’t find the answer here. Did find it on this cpanel forum though:

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

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