DekGenius.com
[ Team LiB ] Previous Section Next Section

Recipe 8.10 Including a Standard Header

Problem

You want to include a header (or footer) in each of your HTML documents.

Solution

Use SSI by inserting a line in all your parsed files:

<--#include virtual="/include/headers.html" -->

Discussion

By using the SSI include directive, you can have a single header file that can be used throughout your web site. When your header needs to be modified, you can make this change in one place and have it go into effect immediately across your whole site.

The argument to the virtual attribute is a local URI and subject to all normal Alias, ScriptAlias, RewriteRule, and other commands, which means that:

<--#include virtual="/index.html" -->

will include the file from your DocumentRoot, and:

<--#include virtual="/cgi-bin/foo" -->

will include the output from the foo script in your server's ScriptAlias directory.

If the argument doesn't begin with a / character, it's treated as being relative to the location of the document using the #include directive.

Be aware that URIs passed to #include virtual may not begin with ../, nor may they refer to full URLs such as http://example.com/foo.html. Documents included using relative syntax (i.e., those not beginning with /) may only be in the same location as the including file, or in some sublocation underneath it. Server processing of the URI may result in the actual included document being located somewhere else, but the restrictions on the #include virtual SSI command syntax permit only same-location or descendent-location URIs.


See Also

    [ Team LiB ] Previous Section Next Section