Archive

Posts Tagged ‘.htaccess’

Force HTML (.htm, .html) files to be parsed as PHP

September 12th, 2009 SiteAdmin No comments

I was asked the following question today, and thought it might be useful to write it up for everyone :

I have an existing web site which is written entirely in HTML.  I have taught myself how to write dynamic code using PHP, and I want to add some PHP code to pages on my existing site.  Here’s the problem : when I upload a page and view it through a browser, I can actually see bits of the PHP code and it is not parsed as PHP. What do I need to do ?

OK, it’s pretty common to have a site written in plain HTML.  A lot of simple sites start out this way.

Now the problem here is simply that the HTML pages are saved as .htm or .html and the web server is not recognizing the need to parse PHP code embedded in those pages.

An easy change to the configuration of the web site will force .htm or .html to have their PHP code parsed and interpreted using PHP.

Simply add the following lines to your .htaccess file :
AddType application/x-httpd-php htm
AddType application/x-httpd-php html


Categories: Technical Tags: , , , ,