Server Side Includes
Write your header and footer once and include them in every page, without any build tools.
Include a file
Put the shared part in its own file, e.g. includes/header.html, and include it where you need it:
<!--#include virtual="/includes/header.html" -->
<h1>About us</h1>
<!--#include virtual="/includes/footer.html" -->
virtual paths starting with / are from your site's top folder; without it they're relative
to the current page. file="footer.html" also works, relative to the current file.
SSI works in .html, .htm and .shtml files, and included files can include others.
Size limits: includes are processed in pages up to 2 MB, and an included file can be up to 2 MB. A larger page is sent exactly as it is, without processing its includes (such pages are usually images or video packed into the HTML; put those in their own files instead and the page loads much faster).
Per-page values
Set a variable before the header and use it inside, for example for the page title:
<!--#set var="title" value="About us" -->
<!--#include virtual="/includes/header.html" -->
<!-- in includes/header.html -->
<title><!--#echo var="title" --></title>
Conditions
Show part of a page only when something is true. The classic use is a shared menu that marks the page you're on:
<nav>
<a href="/"<!--#if expr="$DOCUMENT_URI = /index.html" --> aria-current="page"<!--#endif -->>Home</a>
<a href="/about.html"<!--#if expr="$DOCUMENT_URI = /about.html" --> aria-current="page"<!--#endif -->>About</a>
<a href="/blog/"<!--#if expr="$REQUEST_URI = /^\/blog\//" --> aria-current="page"<!--#endif -->>Blog</a>
</nav>
Style it in your CSS with nav a[aria-current] { font-weight: bold; }. Screen readers announce it as the
current page too.
#elif and #else give other choices; only the first true one is shown:
<!--#if expr="$QUERY_STRING = sent" -->
<p>Thanks, your message is on its way.</p>
<!--#elif expr="$QUERY_STRING = error" -->
<p>Something went wrong. Please try again.</p>
<!--#else -->
<p>Write to us with the form below.</p>
<!--#endif -->
Conditions are written the way Apache has always read them:
$NAME | true if the variable isn't empty |
$NAME = value, $NAME != value | equal, or not (capital letters matter) |
$NAME = /pattern/ | a regular expression matches; != for doesn't. Its groups are $1 to $9 afterwards |
!, &&, ||, ( ) | not, and, or, and grouping |
'About us' | single quotes for text with spaces |
Pages tell their header things with #set: <!--#set var="section" value="shop" --> before the
include, and <!--#if expr="$section = shop" --> inside it.
An address that ends in / is read as a pattern, so to match a folder write one:
$REQUEST_URI = /^\/blog\// is every address under /blog/. Apache 2.4's newer syntax
(v('DOCUMENT_URI') == …, -z, =~) isn't supported. An #if written in it
shows the error message rather than being quietly wrong. pagehaus check, and the
site check Claude and ChatGPT use, report conditions that don't close and files missing in any branch.
Dates and file details
Last updated <!--#config timefmt="%B %e, %Y" --><!--#echo var="LAST_MODIFIED" -->
Today is <!--#echo var="DATE_LOCAL" -->
The brochure is <!--#fsize virtual="/brochure.pdf" -->
Other variables: DOCUMENT_NAME, DOCUMENT_URI (the page's file, such as
/blog/index.html), REQUEST_URI (the address asked for, such as /blog/; on your
404 page, the missing one), QUERY_STRING, HTTP_HOST.
If an include can't be found you'll see “[an error occurred while processing this directive]” in the page:
check the path. #exec isn't supported.
Visitor counter
You are visitor number <!--#counter -->
<!--#counter theme="odometer" color="#f4e7c5" background="saddlebrown" -->
Pagehaus adds one directive of its own: the number of people who have visited your site, as plain text or as digits in boxes in your colours. See visitor counter for the settings, or make one with the counter maker.