Sometimes, you may want your .html or .htm files to be processed as PHP so you can include dynamic code without changing the file extension. This can be done using .htaccess and PHP handlers.
If your hosting uses CloudLinux LSAPI or LiteSpeed API, add the following line to your .htaccess file in the public_html root:
AddHandler application/x-httpd-lsphp .htm .html .shtmlThis tells the server to treat .htm, .html, and .shtml files as PHP.
For other PHP handlers, you can use one of the following methods:
Create a .htaccess file in your public_html directory with these lines:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .htmlTip: Files processed as PHP may require 755 permissions for proper execution.
If the above doesn’t work, try this more comprehensive handler line:
AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml .html .htmor
AddType application/x-httpd-php .php5 .php4 .php .php3 .php2 .phtml .html .htmThis ensures all common PHP file types, plus .html and .htm, are executed as PHP.
Make sure the .htaccess file is uploaded to your public_html or the folder where the .html files reside.
After making changes, clear your browser cache to see the updates.
Using .html or .htm for PHP is convenient, but for best practices, using .php is recommended for dynamic content.