Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process HTML files like PHP

I've been trying to get .html files to process like .PHP files, using the .htaccess file. I've used the following, both of which don't work and trying to access the test page gives me an option to download a file that doesn't exist. How can I fix this?

I tried both of these;

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

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

The idea is to allow includes in my web pages, but still using .html files.

Below is some more code from my .htaccess file, I don't think it's messing with the addType, but I'll post it up.

## Hide .html extension
# To externally redirect /dir/foo.html to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]

1&1 IONOS have decided to only allow me to do it with the following code;

AddHandler x-mapp-php5 .html .htm
like image 504
Switchfire Avatar asked Oct 16 '13 07:10

Switchfire


2 Answers

You need to add

AddHandler application/x-httpd-php .html .htm
like image 109
Funk Forty Niner Avatar answered Nov 09 '22 02:11

Funk Forty Niner


Try this:

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

or

AddHandler x-httpd-php .html .htm

or

<FilesMatch "\.(htm|html|php)$">
SetHandler application/x-httpd-php
</FilesMatch>

or

<FilesMatch "\.(htm|html|php)$">
SetHandler application/x-httpd-php5
</FilesMatch>

Edit: For 1&1 server:

AddType x-mapp-php5 .html .htm

One of these should work

like image 29
Don Avatar answered Nov 09 '22 02:11

Don