Process HTML files like PHP

2019-01-09 13:37发布

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, any ideas?

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

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

AddHandler x-mapp-php5 .html .htm  

3条回答
贼婆χ
2楼-- · 2019-01-09 13:55

You need to add

AddHandler application/x-httpd-php .html .htm
查看更多
姐就是有狂的资本
3楼-- · 2019-01-09 14:05

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

查看更多
做个烂人
4楼-- · 2019-01-09 14:07

You can try the code below also.

AddHandler x-httpd-php .html .htm

OR

AddType application/x-httpd-php .html .htm
查看更多
登录 后发表回答