Php – Is it advisable to force your web server to parse HTML files for PHP code

htmlPHPserver

I can't remember what site I glanced over and picked up that tidbit, but someone suggested that you should keep PHP parsing to .PHP files, and not modify one's webserver's htaccess to include PHP parsing within .HTML files.

Is this true? Is there any generally agreed upon reason as to doing it one way or the other?

Best Answer

I'd say there are two major points to consider when making this, or any, programming/configuration decision:

1. Communication:

By default, HTML files are treated as HTML only. Most developers coming into your environment may assume a default configuration. However, if it's a general practice for system admins to change this, then those developers may assume the HTML files may contain PHP.

I believe that leaving HTML files as HTML-only is a great way to communicate to any other developers that page1.html is a pure-HTML file. This can make it easy for new team members to reverse engineer an existing project if this was the configuration used. In this case, there is no need to open the file for editing as one can simply look at the file extension.

2. Could this Create Unnecessary Overhead?:

Let's say you do have several static HTML files. Well, now your PHP server is going to have to parse your HTML files to look for non-existent PHP code. While I'm sure Apache is fast enough to where this isn't a huge, noticeable problem, it's still something to potentially take into consideration.

Summary:

In summary, my general approach to development is that if it ain't broke, don't fix it. There are a lot of things you can do if you do in fact need to do them, but if you don't have a very strong reason for using non-standard configuration, then it's probably not worth the cost of leaving your potential successor with misunderstandings or confusion.

With that said, I'm not a professional PHP developer, so making HTML files parseable by the server may or may not be considered standard procedure. I would opt to go with whatever is going to be easiest for other PHP developers who join me in my project.