Iain's IT Solutions Ltd.

Iain's IT Solutions Ltd Mobile Nav Menu

Website updates - dynamic menu and executing PHP in a .html page

22-Sep-2011

I've just recently made some interesting changes to this website. I wanted to add a new navigation menu item "Developer tools", which meant adding the link to every page on the site. What I did instead - perhaps what I should have done from the start - is to have the HTML for the menu echoed out to the each page from a PHP function. This way every page has the same PHP function and the menu HTML is written in just one place. Now if I want to add or remove a menu item, I can make the change in just one place, and all pages on the site will instantly be updated.

The thing which lead me this was being able to execute PHP on HTML pages. All the pages on my site have the extension .htm. I've had this site for a long time so didn't want to change this, or any search engine rankings may be lost and any inbound links would also break. What I found was that I could make a change to my .htaccess file which enables PHP within my HTML files to be executed on the server - so I get the best of both worlds - dynamic content and keeping my file extensions/links the same.

This has some exciting uses too in being able to add content management to existing sites which have .html pages, without having to change them to PHP. If someone wants to update a part of their existing site themselves, I could change their .htaccess file to enable PHP to be executed, change the content of their html page to have the content be delivered from a PHP script - pulling the data from a database and give the client an interface to change this database content whenever they like. Much like this blog which pulls the content from a database - so there's just one blogItem.htm page, but it's given an id parameter - this id is looked up in the database and the text pulled. Having the static links to each blog item on the Blog page ensures their picked up by search engines - even though each blog item doesn't have its own page.

I don't believe there's any real difference in .htm or .html file extensions. I went with .htm a long time ago so I've just stuck with it. What I'm actually moving towards is using mod_rewrite to not show any file extensions - so just have slash based urls like: "/about" or "/services/" I've done this on my www.ctrlf.co.uk site




No links allowed (to stop persistent spamming...)




Optional - enter if you want to be alerted when new comments are added