Search code examples
phphtml.htaccessinclude

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

Solution

  • You need to add

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