Knowledgebase: How To
How to Create Server Side Includes
Posted by Joe Rebis (Import) on 20 December 2007 05:52 PM

Server Side Includes (SSI) give you the ability to reuse HTML code by creating a separate file that can be referenced on any page within your site using a special directive (see below). When called in a browser, the code in the SSI file is executed at the same time as main page's HTML. As a result, the page pulls up both sets of code and they are run at the same time.

You can use the same SSI file on any page on your site. In fact, you can even nest SSI's by including other SSI's on your included page. There are special directives that are beyond the scope of this document that can be used as well. e.g. Including the Date and Time. See: http://www.georgedillon.com/web/ssi.shtml

To Activate SSI's on your Site:

  1. Name your base HTML files with the traditional .shtm or .shtml extensions so the web server will know that you intend to use SSI reference on that page. Then include your SSI (Server Side Include) code below.
  2. Submit a ticket with your domain name and we can make normal .html and/or extensions so you can use add a SSI. That's what we do.

To include a SSI on a web page:

  1. Make a file with the code to be included and name it with a .inc, .txt, .shtml or even .html extension. You can do this in notepad. Place in your website's WWWROOT folder or other sub-directory.
  2. Use the code below on that your primary page to reference your included file. You can include multiple SSI's on one page and you can reference the same file on other pages.
  3. Code to Insert to call a SSI:
  4. There are two ways of inserting SSI's into your page. Note, these are just example pages and directories.
  5. <!--#include file="index-menu.inc"--> OR <!--#include virtual="/inc/index-menu.inc"-->

The first way will reference the file relative to the directory the base file is in. The second way references the file relative to the website's root directory (WWWROOT)-- due to the beginning forward slash and the use of the "virtual" attribute. The second method is sometimes better because it ensures your SSI will work on all pages regardless of the sub directory. Note, that in both cases you cannot use the full "http://www.domain.com/inc/index-menu.inc" URL. It must be a relative URL.

See the following site for more information with some fine examples and an SSI tutorial:

http://www.georgedillon.com/web/ssi.shtml

* Please note when researching SSI information note there are some differences between available directives on Windows IIS, Windows with Apache and Linux. We use Windows with IIS.

(589 vote(s))
Helpful
Not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).

Copyright © 2015 EPhost, Inc. All rights reserved.