How to enable Server Side Include (SSI) with .htaccess file

Server Side Includes (SSI) is a simple interpreted server-side scripting language used almost exclusively for the Web.The most frequent use of SSI is to include the contents of one or more files into a web page on a web server. Server Side Includes are useful for including a common piece of code throughout a site, such as a page header, a page footer and a navigation menu. Conditional navigation menus can be conditionally included using control directives.

In order for a web server to recognize an SSI-enabled HTML file and therefore carry out these instructions, either the filename should end with a special extension, by default .shtml, .stm, .shtm, or, if the server is configured to allow this, set the execution bit of the file.

This is particularly useful, for example to include a navigation menu in your HTML documents, it allows you to use one document to display the navigation menu in all your other documents. This saves disk space and means if you need to update the content, you only need to modify one file.

Two examples of HTML tags you would use to call SSI documents are shown below, these would be placed in your HTML document:

<!–#exec cgi=”/cgi-bin/script.cgi”–>

Above Code would load the CGI script ‘script.cgi’ which is located in the ‘cgi-bin’ directory.

<!– #include virtual=”../quote.txt” –>

Above code the text file quote.txt in the uplevel folder.It is important to use a relative URL, not a path or full URL. With one change of the quote.txt file, all pages that include the file will display the latest daily quotation. The inclusion is not limited to files, and may also be the text output from a program, or the value of a system variable such as the current time.

In order to use SSI in your website (Ask your web hosting provider whether they allow you to run SSI in your website first), you need create a .htaccess file with following code:


AddHandler server-parsed .html
AddHandler server-parsed .shtml
AddHandler server-parsed .htm

above codes tell the apache web server to allow server side includes in documents with the file extension ‘.html’, ‘.shtml’ and ‘.htm’. If you only want it to run in .html file extension, you just need:


AddHandler server-parsed .html

Steps to enable SSI Server Side Includes in Cpanel

Leave a Reply

Your email address will not be published. Required fields are marked *