- 1 Vapor IO Brings OpenDCRE to General Availability
- 2 VMware Takes the Wraps Off vRealize Automation and vRealize Business
- 3 Microsoft Previews Hyper-V Containers for Windows Server 2016
- 4 Mirantis Led FUEL Project Gets Installed Under OpenStack Big Tent
- 5 Red Hat Enterprise Linux 7.2 Adds Security, DR Features
Apache Guide: Introduction to Server Side Includes, Part 2
This is the second of a three-article series on SSI. In the first article, we talked about how to enable SSI on your server and passed on some very basic examples. In this article, there will be more examples, and we'll talk about some somewhat more involved things that you might want to do with SSI. In the final article, we'll talk about the more advanced features of Apache SSI, including conditional statements.
In the last article, we mentioned that you could use SSI to inform the user when the document was most recently modified. However, the actual method for doing that was left somewhat in question. The following code, placed in your HTML document, will put such a time stamp on your page. Of course, you will have to have SSI correctly enabled, as discussed in the last article.
<!--#config timefmt="%A %B %d, %Y" --> This file last modified <!--#flastmod file="ssi.shtml" -->
Of course, you will need to replace the
ssi.shtml with the
actual name of the file that you're referring to. This can be inconvenient if
you're just looking for a generic piece of code that you can paste into any
file, so you probably want to use the
<!--#config timefmt="%D" --> This file last modified <!--#echo var="LAST_MODIFIED" -->
For more details on the
timefmt format, go to your favorite
search site and look for
ctime. The syntax is the same.
If you are managing any site that is more than a few pages, you may find that making changes to all those pages can be a real pain, particularly if you are trying to maintain some kind of standard look across all those pages.
Using an include file for a header and/or a footer can reduce the burden of
these updates. You just have to make one footer file, and then include it into
each page with the
include SSI command. The
element can determine what file to include with either the
attribute, or the
vitrual attribute. The
attribute is a file path, relative to the current directory. That
means that it cannot be an absolute file path (starting with /), nor can it
contain ../ as part of that path. The
virtual attribute is
probably more useful, and should specify a URL relative to the document being
served. It can start with a /, but must be on the same server as the file being
<!--#include virtual="/footer.html" -->
I'll frequently combine the last two things, putting a
LAST_MODIFIEDdirective inside a footer file to be included. SSI directives can be contained in the included file, and includes can be nested - that is, the included file can include another file, and so on.
In addition to being able to
configthe time format, you can also
configtwo other things.
Usually, when something goes wrong with your SSI directive, you get the message[an error occurred while processing this directive]
If you want to change that message to something else, you can do so with the
errmsgattribute to the
configelement:<!--#config errmsg="[It appears that you don't know how to use SSI]" -->
Hopefully, end users will never see this message, because you will have resolved all the problems with your SSI directives before your site goes live. (Right?)