mod_include to the rescue

After working with content management managements for well quite awhile now, the thought of creating more than seven (more than five, less than ten) static pages for a client makes me cringe. Why? I am spoiled by using template driven solutions. With templateing, if I need to make a header change, I change it one place and I am done with it. With using static .html pages, I have to make the change to all the pages. I have grown very reliant on using find and replace, but then – because of the person I am – I have to go back and make sure everything looks right.

I am currently wrapping up a project where I was not able to use a content management system, PHP, or any sort of database. No, this is not 1998, this is present day. For decisions I will not get into, this was the situation, no getting around it. This web site has about 75 static pages and around the twentieth page I started to sweat when the client wanted a major layout change. After emailing someone technical in the department I found out they did allow the use of Server Side Includes (SSI) by way of the mod_include module in Apache. My life became much easier after this past weekend as I converted all the pages to be .shtml pages (needed for SSI). By using SSI, I was able to create common files (header, footer, side links, navigation) so any changes to the common elements, and I just need to touch one file instead of all 75 pages.

What you need to use SSI on the server end:

  • Apache with mod_include
    enabled
  • Apache configuration must have the proper AddType and AddHandlers set up: AddType text/html .shtml AddHandler server-parsed .shtml
  • Apache configuration must also have the directive set up for the appropriate directorys (): Options +Includes

What you need to use SSI on the client/page end:

  • Name all files you want to have SSI elements in them to include the .shtml extension so Apache knows to parse these files properly
  • Use the following syntax when you want to include a file: when you want to “inlcude” some common code such as a header or footer. (please see the mod_include documentation for all syntax)

Apache’s mod_includes also gives you the ability to include CGI files, show modification dates, date and time, the user name who last modified the file, etc. Lesson learned: if someone approaches you about creating a “simple” static web site, look into if SSI is an option!
[tags]Apache, mod_include, SSI[/tags]