8.11. 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.
Tip
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access