phphtml.htaccesswebbluehost

How to allow execution of PHP in HTML file using .htaccess


I want to run .html files as .php, but can't seem to get it to work. I have tried to add all of the below to my .htaccess file, one at a time. None of the below seem to work.

AddType application/x-httpd-php .html .htm
AddHandler application/x-httpd-php5 .html .htm
AddType application/x-httpd-php72 .html .htm
AddHandler application/x-httpd-php5 .html .htm
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
<FilesMatch "\.html$">
 ForceType application/x-httpd-php
</FilesMatch>
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
Options +ExecCGI
 AddType application/x-httpd-php .php .html
 AddHandler x-httpd-php5 .php .html

I know PHP works since I was able to create a document .php and view the version on the website using:

<?php
echo 'Current PHP version: ' . phpversion();
?>

It returned: "Current PHP version: 7.2.21"

Some notable information: I am hosting the website on Bluehost and the .htaccess file looks like this at the moment:

# Redirect HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Solution

  • Have you tried this?

    RewriteRule ^([^\.]+)$ $1.html [NC,L]
    

    Take a look at: https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/