Using server side includes (SSI)
Overview
This article explains how to use SSI (Server Side Includes) in your web pages from the designated files. SSI is a simple scripting language that can easily be embedded in existing HTML files.
READ ME FIRST
This article is provided as a courtesy. Installing, configuring, and troubleshooting third-party applications is outside the scope of support provided by (mt) Media Temple. Please take a moment to review the Statement of Support.
READ ME FIRST
This article is provided as a courtesy. Installing, configuring, and troubleshooting third-party applications is outside the scope of support provided by (mt) Media Temple. Please take a moment to review the Statement of Support.
Using SSI
There are two main approaches to using SSI in your web pages. The first is to use a unique file extension for all of your files that include SSI, such as .shtml. The other is to add execute permissions to every HTML file that has SSI in it. While it is possible to process all .html files for SSI, this is not recommended. It will add to the load times of pages that do not include any SSI.
- Please see our article on the .htaccess file for instructions on the best way to create and upload this type of file.
You will need to add the following lines to your .htaccess file, after any other Options directives:
Unique extension method
This will allow all files with the designated extensions to be processed for SSI. You can add or remove additional file extensions as desired. In this example, all files with the extensions .shtml, .stm, and .shtm will be processed for SSI.
Filename: .htaccess
Options +Includes
AddHandler server-parsed .shtml .stm .shtm
NOTE:
If you get a 500 error on one of your web pages after adding an extension to your .htaccess file for processing, please go back and remove that extension from the list. For example, if you do add the .html extension for processing, you may have other HTML comments in your code which are not intended to be read by the SSI interpreter, and which will cause errors if they are read.
If you run into this issue, you might want to try the execute permissions method instead.
Execute permissions method
This directive will cause all files that have the execute permission set to be processed by the server.
Filename: .htaccess
Options +Includes
XBitHack on
You will now need to add execute permissions to the HTML files that you want the server to process for SSI. You can do this through your FTP software, or with the following SSH command:
chmod +x example.html
It is also possible to combine both directives in your .htaccess file, if you need to process files with unique extensions and files with the execute permission set.
Upload the file
You should now upload your .htaccess file to your server via FTPFTP. You should upload the file to /domains/example.com/html/ /var/www/vhosts/example.com/httpdocs/ or to a subfolder, if you plan to run SSI only in a particular subfolder.
Testing
Add the following line of code to your file for testing:
Filename: example.shtml
<!--#echo var="DATE_LOCAL" -->
When you visit this page in your browser, you should see the date displayed.
With PHP output
You may encounter a "Content Encoding Error" when using SSI in conjunction with a PHP output page. A simple work around would be by disabling gzip. You can easily do this by adding the following line to your .htaccess file:
SetEnv no-gzip dont-vary
Resources
For more information on SSI, please visit http://httpd.apache.org/docs/howto/ssi.html.