Running .htm or .html files through PHP in Apache

I recently took over a project where the previous developer saved all of his PHP files as .htm files. This allows the viewer to think he's looking at a plain Jane HTML file, when, in reality, he or she is loading a PHP file. The advantage being an unscrupulous user may try and hack the server, knowing it's running PHP.

To update your server to do this, simply create a .htaccess file and put it in your web root. From there, simply add the following into the file:

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

Save the .htaccess file and reload your page. If you have a PHP file saved as a .htm (or any other file extension, really), it should load correctly. Any includes calls, functions, etc. should load as expected.

NOTE: Your web server needs to be setup so that .htaccess files work correctly.


Back to the Top