One SSI directive to save all programming muggle’s effort and time

by Yang Yang on April 1, 2008

SSI stands for Server Side Includes that is a default module in Apache web server. In essence, it provides a very simple mechanism to include one HTML file in another one, thus tremendously reducing redundant coding and increase the ease of later maintenance.

So, to get 80% out of SSI, the only directive you pretty much need is this:

<!--#include virtual="/parts/footer.html" -->

Make sure ‘include’ is immediately after ‘#’ without any blank spaces.

As the file name suggests, you are adding a common site footer. You can do this to all other pages on your site, making updating footer very easy because you only need to modify /parts/footer.html to get the changes done.

To get 80% our of SSI, you only need one directive, that is <!–#include virtual=" … " –>. It’s the essence I believe. And to get the rest 20%, you might also want to know about these handy ones (incomplete, just examples I think that will amuse you):

Get file size:

<!--#fsize virtual="/parts/ads.html"-->

Get last modified date:

<!--#flastmod virtual="index.html"-->

Get visitor IP address:

<!--#echo var="REMOTE_ADDR" -->

Get today’s date:

<!--#echo var="DATE_LOCAL" -->

Setting and getting a variable:

<!--#set var="name" value="Rich" -->
<!--#echo var="name" -->

You can even do some concatenation:

<!--#set var="firstname" value="Rich" -->
<!--#set var="lastname" value="Mond" -->
<!--#set var="name" value="${firstname} ${lastname}" -->

You get the idea. =) However, to get SSI to work on your server, you might need to add the following directives to httpd.conf (that is, if you are your own server administrator) or .htaccess (if you are on your own by shared hosting):

Options +Includes

For further reading, please refer to:

  1. Apache SSI Tutorial
  2. Kavoir SSI Framework
  3. wikipedia SSI
  4. HTML Code Tutorial, SSI help forum is a good place to go seeking for help. I’m there by the name of yangyang. =)

Previous post:

Next post: