Apache2- Enabling SSI for HTMLs using .htaccess

Server-side includes (SSI) are the recommended way of including one html file in another. To enable SSI for file types like .html, .htm or .shtml on Apache2 server, you need to follow below steps:

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:

a2enmod include
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
AddHandler server-parsed .html

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.

/etc/init.d/apache2 restart

Reference: MOD_INCLUDE

(Visited 286 times, 1 visits today)