A Different Approach to Parsing HTML as PHP
On occasion it’s necessary for me to process HTML files as PHP. Reasons vary, but usually it’s because the clients web site was originally set up as static HTML and we need to process dynamic content, but due to SEO reasons, we can’t change the file extensions.
Generally a simple .htaccess file can handle this process for you and make simple work of the informing the server to parse HTML as PHP. Some people complain of the load that this can put on the server, but I think this argument is unfounded.
What should be a simple solution, can often turn into an enormous problem. Things being what they are, we ran into a server where our simple two line .htaccess file failed to do the job. All manner of adjustments made between the .htaccess file, changes made by our server admin to the Apache httpd.conf file, all failed.
So in the event that these lines don’t work (while all of the Google results say that they do…)
1 2 | AddType application/x-httpd-php .html AddHandler application/x-httpd-php .html |
What we had to do instead was test to see if a version of the .html or .htm file existed. If it did, then our solution accessed that file as requested, if not, then it looks for a .php version of the same filename.
1 2 3 | RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+)(\.htm|\.html)$ $1.php [L] |
In the end what you end up with is, no broken links in the search engines to the .html or .htm files and what everyone sees is the output of the .php file if the requested .html or .html file doesn’t exist.

January 5th, 2010 at 7:36 pm
Greetings, I like your blog very much. It has related info in it. I came here from search engine aol while was searching for website hosting info. Keep working on blog I d place bookmark, thanks.