Apache Server Side Includes (SSI) can be used add dynamic content to web pages, add JavaScript, reuse HTML code, and more.
Enabling Server Side Includes
For our shared and reseller web hosting accounts, Server-Side Includes are enabled by default for files that have a .shtml
extension. However, you may want to use Server-Side Includes with other types of files, such as .html or .htm files.
To do this, create an .htaccess
file in your account's document root (public_html) directory, or in the subdirectory where you want to use Server-Side Includes. Add the following text to the .htaccess file:
Options +Includes AddType text/html .html AddOutputFilter INCLUDES .html AddType text/html .htm AddOutputFilter INCLUDES .htm
These directives demonstrate how to enable Server Side Includes for files that have a .html or .htm extension, but you can easily add other file extension types as well.
Note: It is not possible to use cross-domain or cross account SSI on our servers.
How to use Server-Side-Includes
It's very easy to add your own dynamic content! Here's how:
Reuse HTML
A common use of SSI is to reuse HTML in multiple pages. For example, you want to include HTML code for a header or footer in every page on your web site. You could copy this HTML manually to each page, but what happens when you want to make a change to the footer? You would have to edit each file individually.
SSI provides an easy solution to this problem. Continuing our example, you can create a header.html
page that contains the footer code, and then reference the header.html file in your web site pages by using the virtual
attribute of SSI: include virtual="header.html"
.
SSI commands should always be enclosed in the following fashion:
<! --#insert command-- >