Get Apache to parse .html files as PHP
Posted January 10th, 2010 in Apache and PHP
When PHP is installed in Apache files with the .php extension are interpreted as PHP scripts. It is possible to make any file extension be parsed as PHP including .html.
Make a .html file be parsed as PHP
This can be done at the following levels:
- The main Apache configuration which will apply to all virtualhosts
- An individual <virtualhost>
- In an .htaccess file
It can either be done for everything, or using e.g. a <Directory> block to limit it to a specific directory. With an .htaccess file it will apply to the directory the .htaccess file is in and all subdirectories below that one.
Simply add the following line to the appropriate location as noted above:
AddType application/x-httpd-php .html
Now all files with a .html extension will be parsed as PHP.
A note of warning: it is not generally a good idea to make all .html files be parsed as PHP. If they do not contain any PHP code then they will still invoke the PHP interpreter which will cause additional overhead on the web server. Make sure you have good reason to do so, and ideally limit it to an individual virtualhost and then possibly to particular directories.
Related posts:
- Password protect a directory with Apache (Tuesday, June 29th 2010)
- Disable PHP in a directory with Apache .htaccess (Monday, March 29th 2010)
- Set PHP configuration options with an Apache .htaccess file (Thursday, April 16th 2009)
- Changing the .htaccess filename in Apache (Thursday, April 17th 2008)

Comments
blog comments powered by Disqus