Apache Guide: Introduction to Server Side Includes, Part 2

執筆者
Rich Bowen
Rich Bowen
Published: Jun 19, 2000
Updated: Nov 10, 2020
3 minute read
ServerWatch のコンテンツおよび製品のおすすめは、編集上の独立性を保っています。パートナーへのリンクをクリックすると、当社が報酬を得る場合があります。 詳細を見る



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.

When was This Document Modified?

In the next installment of his SSI series, Rich Bowen passes on some more advanced examples of how you can implement useful SSI features on your Apache Web server–complete with code.

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 LAST_MODIFIED variable
instead:

        <!--#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 include
element can determine what file to include with either the file
attribute, or the vitrual attribute. The file
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
served.

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

I'll frequently combine the last two things, putting a
LAST_MODIFIED directive 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.

What Else can I Config?

In addition to being able to config the time format, you can
also config two 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
errmsg attribute to the config element:

        <!--#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?)

Rich Bowen

Rich Bowen is a ServerWatch contributor.

ServerWatch Logo

ServerWatch is a top resource on servers. Explore the latest news, reviews and guides for server administrators now.

TechnologyAdvice が所有・運営しています。 © 2026 TechnologyAdvice. 無断転載を禁じます

広告主に関する開示:このサイトに掲載されている製品の一部は、TechnologyAdvice が報酬を受け取っている企業のものです。この報酬は、製品がこのサイトのどこにどのように表示されるか(表示される順序など)に影響する場合があります。TechnologyAdvice は、市場で入手可能なすべての企業やすべての種類の製品を掲載しているわけではありません。