1

i asked a question if i can execute html files as php files and i got those answers

AddType application/x-httpd-php5 .php .html

and another answer

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

and here is another one

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

and i got 1 problem when i used to write any condition to add type it send me to download the page instead of run it for example if i have a file index.html which have php code after i create the .htaccess and write

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

then try to navigate the link it send me to download index.html instead of run it

Marco
  • 842
  • 6
  • 18
  • 42
  • Original question: http://stackoverflow.com/questions/7123560/small-problem-with-htaccess-file – Marc B Aug 19 '11 at 20:46
  • Possible duplicate of [Using .htaccess to make all .html pages to run as .php files?](https://stackoverflow.com/questions/4687208/using-htaccess-to-make-all-html-pages-to-run-as-php-files) – kenorb Nov 06 '17 at 14:15

4 Answers4

3

AddType is used to assign a MIME type to a file suffix.

F.e. to override the MIME type of an PDF *sic

AddType text/plain .pdf

This will force the browser to load and show a PDF as plain text, because server is sending the text/plain MIMe type. But many applications handle files by content and not by suffix.

RemoveHandler

This is unnecessary, you don't want to remove anything from the standard configuration.

AddHandler handler-name .htm

This should do it, but it depends on your server configuration. You need the right "handler-name".

Standard handler-name for most Apache servers with PHP installed is

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

but it could differ and it depends on your configuration. If you are using a shared or managed hosting without access to the Apache configuration file, you should ask your hoster.

I was using shared hosting with handler-names like

AddHandler php4-cgi .php .html

or

AddHandler php52-cgi .php .html

and another was using totally different way like

AddType x-mapp-php5 .php .php5 .htm .html

Otherwise have a look on your Apache configuration file. This page may be helpful to find the right section and to adapt.

Eddy Freddy
  • 1,820
  • 1
  • 13
  • 18
1

Did you try:

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

?

Shef
  • 44,808
  • 15
  • 79
  • 90
0

Exactly the same problem, the basic code forces page download, but this:

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

...rectified the issue & worked perfectly.

kenorb
  • 155,785
  • 88
  • 678
  • 743
sean
  • 1
0

if you are using fcgi none of the above will work ; you need

<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>

Display name
  • 420
  • 5
  • 20