SSI Directive Explorer
Understanding SSI Directives
Server Side Includes (SSI) allows you to embed dynamic content into static HTML pages. These directives are processed on the server before the page is sent to the browser.
Common Directives
#include Inserts content from another file
#echo Displays server variables like dates
#set Creates reusable variables
#config Changes formatting behavior
How It Works
- Request a .shtml file
- Server detects SSI directives
- Directives are replaced with content
- Final HTML is sent to browser
Try SSI Directives
Real-World Example
Here's how SSI helps maintain consistent headers and footers across multiple pages:
When a visitor loads index.shtml, the server merges the header and footer with the main content, creating a complete page without duplicating code.
Server Side Includes is a simple server‑side scripting language that lets you embed dynamic content into static HTML pages. When a web server parses an .shtml
file, it looks for special directives and replaces them with the requested data before sending the page to the browser.
Key Takeaways
- SSI works by inserting small code snippets into static pages at request time.
- The most common directive is
#include
, used for headers, footers, navigation bars, and reusable snippets. - Apache and Nginx both support SSI with minimal configuration.
- SSI is lightweight compared with full‑blown server‑side languages like PHP or ASP.NET.
- Typical pitfalls include file‑path errors and disabled SSI on the server.
How SSI Works - Step by Step
- The client requests a page that ends with
.shtml
. - The web server detects the
.shtml
extension and activates its SSI parser. - The parser scans the file for directives that start with
<!--#
and end with-->
. - Each directive is processed - for
#include
the server reads the target file and injects its contents. - After all directives are resolved, the final HTML is sent back to the browser.
Because the processing happens on the server, users never see the SSI code; they only receive the rendered HTML.
Common SSI Directives
Below are the directives you’ll encounter most often:
#include file="relative/path/to/file.html"
- inserts another file.#include virtual="/absolute/url/to/file.html"
- inserts a file based on the URL path.#echo var="DATE_LOCAL"
- writes the server’s current date and time.#config sizefmt="bytes"
- changes how file sizes are displayed.#set var="myVar" value="some value"
- defines a reusable variable.

Real‑World Example: Header and Footer Includes
Imagine you run a small marketing site with ten pages, each sharing the same header and footer. Updating the design manually on every page would be a nightmare. SSI solves this with just two extra files.
First, create header.html
and footer.html
in the includes/
directory:
<!-- header.html -->
<header>
<h1>My Marketing Site</h1>
<nav>
<a href="/index.shtml">Home</a> |
<a href="/about.shtml">About</a> |
<a href="/contact.shtml">Contact</a>
</nav>
</header>
<!-- footer.html -->
<footer>
<p>© 2025 My Marketing Site. All rights reserved.</p>
<p>Last updated: <!--#echo var="DATE_LOCAL" --></p>
</footer>
Now, each page (e.g., index.shtml
) only needs two SSI lines:
<!--#include file="includes/header.html" -->
<main>
<h2>Welcome to our homepage</h2>
<p>Lorem ipsum dolor sit amet...</p>
</main>
<!--#include file="includes/footer.html" -->
When a visitor loads index.shtml
, the server pulls the header and footer, merges them with the main content, and serves a complete HTML page. Updating the header file instantly updates every page on the site.
Enabling SSI on Popular Web Servers
Two of the most common servers support SSI out of the box, but you still need to turn it on.
Apache HTTP Server is a widely used open‑source web server that supports SSI out of the box. Add the following lines to your httpd.conf
or a site‑specific .htaccess
file:
AddType text/html .shtml
AddHandler server-parsed .shtml
Options +Includes
After restarting Apache, any file ending in .shtml
will be parsed for SSI directives.
Nginx is a high‑performance web server that can also handle SSI. Include this block in the relevant server
section:
location / {
ssi on;
ssi_types text/html;
}
Unlike Apache, Nginx does not need a special file extension; you can enable SSI for any text/html
response.
SSI vs. PHP Include - Quick Comparison
Feature | SSI | PHP include |
---|---|---|
Complexity | Very low - plain text directives | Higher - requires PHP interpreter |
Performance impact | Minimal - only file reads | Higher - script execution overhead |
Programming logic | None (only includes, echoes, configs) | Full language support (loops, conditionals) |
Typical use case | Reusable page fragments on static sites | Dynamic applications needing logic |

Pros, Cons, and Common Pitfalls
Server Side Includes shine when you need a lightweight way to share snippets across many static pages. Here’s a quick cheat sheet:
- Pros: easy to learn, no extra runtime, works on most servers, reduces duplication.
- Cons: no real programming capabilities, limited to file inclusion and simple variable handling.
- Pitfalls:
- File‑path mistakes - always verify relative vs. virtual paths.
- SSI disabled by default - remember to enable it in server config.
- Security risk - never include files based on user input.
Next Steps & Troubleshooting
If your SSI directives aren’t rendering, try these steps:
- Confirm the file extension matches the server’s SSI configuration (
.shtml
for Apache, anytext/html
for Nginx). - Check the server error log for messages like “SSI directive not allowed”.
- Verify file permissions - the server must read the included files.
- Test a simple echo:
<!--#echo var="DATE_LOCAL" -->
. If this works, the parser is active, and the issue is probably a path error. - Make sure
Options +Includes
(Apache) orssi on;
(Nginx) is inside the correct<Directory>
orserver
block.
Once everything is working, you can start adding more sophisticated directives like #set
and #if
to create basic conditional content.
Frequently Asked Questions
What file extensions trigger SSI processing?
On Apache the default is .shtml
, but you can enable SSI for any extension using AddHandler server-parsed .html
. Nginx processes SSI for any response with the text/html
MIME type when ssi on;
is set.
Can SSI include files from another domain?
No. SSI works only on files that the web server can read locally. To pull external content you’d need a server‑side language like PHP or a reverse‑proxy solution.
Is SSI safe for public websites?
It’s safe as long as you never expose user input in an #include
path. Stick to static file paths and keep the included directory outside any uploadable area.
How do I debug a broken SSI directive?
Enable error logging in your server config, then check the log for messages like “SSI directive not allowed” or “File not found”. You can also temporarily replace the directive with a plain HTML comment to see if the page renders at all.
When should I choose SSI over a full‑stack framework?
If your site is mostly static and you only need to reuse headers, footers, or simple date/time stamps, SSI is faster to set up and consumes fewer resources. For anything that needs business logic, database access, or user authentication, a full‑stack language is a better fit.