Main Content

.php or .html extension? Morally Static Pages

Archive - Originally posted on "The Horse's Mouth" - 2007-09-17 19:07:09 - Graham Ellis

You'll find many pages on our web site with .php extensions, and many more with .html extensions. "So the .php files contain executable content and the .html files do not" you may think. No - not exactly; in practise almost every page actually contains some PHP / Script elements. So WHAT, WHY, HOW?

WHAT ... All pages which contain data which is essentially unchanging have extensions that end in .html, but pages which are essentially dynamic are classified as .php.

I describe the pages that are unchanging as Morally Static Pages, and examples might include /share/prisonbridge.html and /mouth/17_Differing-tastes.html, both of which are generated from databases; in essence they don't ever change a great deal unless I modify the content, but you will see small changes from time to time in the list of nearby places on the Prison Bridge page, or in the "see also" column of the Differing Tastes page.

We have a number of truly dynamic pages. For example our Site Map Page will change to give you a site map relative to your current location each time you call it up, and our Image Library Search will vary depending on what pictures have recently been added and what you're searching for.

WHY ... If you are looking for a page, then you'll feel confident that a .html file is one that you can bookmark, come back to - a simple soul that's going to vary little and you can rely on to stay the same until the site owner changes it. By contrast, if you find a page that's saying that it's dynamic, it probably is and you'll treat it with a degree more respect. You may bookmark it, but you'll be aware that results may change rather more frequently, and you'll treat it with rather more circumspection.

The same thing applies to the best search engine crawlers, I think. In amongst all the various factors they take into account, they'll look at how often a page changes / is likely to change and the extension offers a good clue. So the application of different extensions is an aid to them as they're indexing your page too, helping them to categorise as appropriate.

HOW ... We're using the .htaccess file and Apache httpd's mod_rewrite to provide the facilities that we need. At the very simplest, a line such as
AddType application/x-httpd-php .html
added to the httpd.conf (or appropriate .htaccess) file(s) will trigger the web server to parse all .html files in case they contain PHP. In a more extreme case, a directive such as
RewriteRule ^(.*)\.htm /share/index.php?pagename=
will take all .html and .htm requests and divert them to index.php, with a parameter called pagename being passed in. This is the basis under which a whole directory of Morally Static Pages can be generated on the run, without there being a single truly static page present at all.