How to Install SSI
One of the challenges of updating a website is when you need to redesign a part of a Web page that needs to be reflected on all Web pages. Server Side Includes (SSI) are files that make this whole process much easier by inserting the content of a single file and having it reflected on other Web pages. Common uses of SSI are in navigation bars, headers and footers or other Web page elements that remain virtually unchanged when navigating from one page to another on a website.
Instructions
-
-
1
Ensure that your hosting server supports the use of SSI. Some common Web servers that support SSI include Apache, Internet Information Service (IIS) from Microsoft and Lighttpd.
-
2
Open the .htaccess file found in the root directory of your Web Server and add the following lines in the file:
Addtype text/html .shtml
AddHandler server-parsed .shtml
Options Indexes FollowSymLinks Includes
-
-
3
Save the file as .htaccess and upload it to the root directory with the rest of your Web pages.
-
4
Use SSI files on many Web pages simultaneously. Add the line below to the .htaccess file:
DirectoryIndex index.shtml index.html
The above line tells the server to look for the index file with the SSI first before pulling the normal index.html file which contains no SSI. This line is important on hosts that do not serve the default index.html file whenever a person searches for the website by just including the URL with adding a specific Web page.
-
5
Add the "#include" line to the HTML file where the external files are to be imported as shown below:
<!--#include virtual= "/includes/navigation.ssi" ->
Always ensure that the SSI file resides on the path defined. In this case it resides in the folder called "Includes" located in the root directory of the Web Server. Add the above line where you want the code snippets in your SSI files to be imported in your HTML or PHP page.
-
1
Tips & Warnings
Creating a .htaccess in Windows is not possible since Windows does not allow the creation of a file starting with a dot. To get round this problem, upload the file as a text file and then rename it on the server.
When adding SSI in PHP, use the format below:
<?php
@includes ("name of file");
?>
It is possible to have an "Include" file contain other "Includes" as well, which are evaluated first before the pages are rendered. However, this can slow down the server since more time is needed to locate and retrieve each of these files. Include files should only be used when it is absolutely necessary since they affect the performance of a website.
References
Resources
- Photo Credit Comstock/Comstock/Getty Images