Meeshal Meeshal - 1 year ago 72
Apache Configuration Question

How to get a PHP file to run with an ".html" extension?

I have to execute PHP codes in a HTML file, but my server not doing it. I added a handler

AddHandler application/x-httpd-php .html .htm
but still it's not responding to the code.

The code I tried to execute

<!DOCTYPE html>
<p>the file name is <?php echo $url; ?></p>
</body> </html>

and the result is "the file name is"

First image

it should be "the file name is test.html"

Second image

I checked the server software version via
it say this "Apache Phusion_Passenger/4.0.10 mod_bwlimited/1.4 mod_fcgid/2.3.9". now what ?

I don't even know that it is. Please tell me what server my web host is using and how can I run PHP codes in a HTML file?

Answer Source

You can try one of the following (probably, add to your .htaccess):

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


<FilesMatch ".+\.html$">
    SetHandler application/x-httpd-php