If you’re looking to modularize your HTML code by including shared headers, footers, or snippets, Server-Side Includes (SSI) is a simple and effective solution. This guide walks you through enabling SSI for .html
, .htm
, and .shtml
files using Apache 2 and .htaccess
.
Step 1: Enabling mod_include on Apache
Make use mod_include must be enabled and is running. This module is generally available with the default Apache 2 setup. To enable it on Debian, execute the following command:
sudo a2enmod include sudo systemctl restart apache2
Step 2: Set XBitHack flag
. XBitHack allows to parse files for server side includes as long as they have the execution bit set. Make below configuration in .htaccess file:
XBitHack On
Step 3: Configure File type for SSI
Add file types to be enabled for server side include (SSI) in.htaccess configuration like below:
AddType text/html .html .htm .shtml AddHandler server-parsed .html .htm .shtml
Add ‘Includes‘ to the Options directive in.htaccess:
Options -Indexes FollowSymLinks Includes
So, the overall SSI configuration for various html file types would be:
XBitHack On AddType text/html .htm AddType text/html .shtml AddHandler server-parsed .html AddHandler server-parsed .htm AddHandler server-parsed .shtml Options -Indexes FollowSymLinks Includes
Step 4: Restart Apache
Finally restart Apache to make the changes reflected.
sudo systemctl restart apache2
Reference: MOD_INCLUDE
Conclusion
SSI is still a valid and lightweight method for HTML content modularization on Apache servers, especially for static or CMS-based sites. Ensure you configure it securely and use it in performance-aware environments.