How to parse HTML files as PHP on an Apache web server


Someone asked me today for help with their PHP website.  He was trying to parse HTML files as PHP on his Apache webserver. This is very easy to do using the .htaccess file but he just could not seem to get his files to parse using the instructions he found on Apache’s website:

AddType application/x-httpd-php .html

The thing to remember with something as diverse as Apache and PHP, different hosts will have different configurations. For example, some hosts runs both PHP4 and PHP5. In this case, he was hosting the company website through HostGator. This is what had to be added to the htaccess file to get it to correctly parse the files:

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

With other hosts, you can get away with:

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


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


AddHandler x-httpd-php .html .htm

And still yet, some hosts require both AddHandler and AddType directives for it to work correctly:

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

Hope this helps. Leave a comment if you have any questions.

About Jason Samuel

Jason Samuel is a Solutions Architect and Security Practice Lead working at Alchemy Tech Group in Houston, TX with a primary focus on mobility, virtualization, and cloud technologies from Citrix, Microsoft, & VMware. He also has an extensive background in web architecture and information security. He is certified in several technologies and is 1 of 50 people globally that is a recipient of the prestigious Citrix Technology Professional (CTP) award. He is 1 of 28 people in the world that is an Atlantis Community Expert (ACE). He is a featured author on DABCC which provides the latest IT Community News on Cloud, Data Center, Desktop, Mobility, Security, Storage, & Virtualization. In his spare time Jason enjoys writing how-to articles and evangelizing the technologies he works with.

Recommended for you

Leave a Reply

Your email address will not be published. Required fields are marked *