Running HTML pages with PHP code
Running HTML pages with PHP code

How do I execute PHP code in regular pages (.html files)?

It is possible to execute PHP code within regular .html or .htm files. To do so, you must instruct Apache that .html and/or .html files must be first parsed by the PHP module before being sent to the person loading the page. To do this, you will need to create or edit the .htaccess file in the directory you require this in. Please note that .htaccess directives operate recursively, and will therefore apply to any subdirectories as well. Most people will make this change in their main public_html directory so that it applies to any/all subdirectories in their site.

The entries you will need to add to your .htaccess file are as follows:

RemoveHandler .html .htm

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

Leave a Reply