Incommunique

Powered by a whole foods plant based diet, a well dressed penguin and an over-active imagination

Embedding PHP in .html files

One of the little volunteer jobs I do is as webmaster for The Katharine Susannah Prichard Writers’ Centre. For the most part the pages are static and I don’t do much at all. One thing that has bothered me though is that the menu code was embedded in every single page (my fault). I wrote a perl script to update each page for me but I still had to re-upload them all individually (KSP’s ISP does not allow shell access…). Along with a desire to implement a few bits of dynamic content I thought PHP might be a good solution but I didn’t want to have to rename all the pages to .php. Not only would that mean all the internal links would need updating but any external links would break too. A quick bit of Googling around and I found this trick: create a .htaccess file with the following line in it-

AddType application/x-httpd-php .php .php3 .phtml .html

now all .html files will be processed as php scripts which is exactly what I wanted. Want another item in the menu? Simple, change one line in menu.php and it’s done! Not only that but the individual pages are suddenly simpler and will be easier to maintain. Now to write the code for that dynamic content…

Update: and if you or your ISP is not running mod_php you need to add this line as well-
Action application/x-httpd-php /cgi-bin/php-handler


Share