Loading...

Knowledge Base
Up to 75% off on hosting for WordPress websites and online stores

Server Side Includes: Allow SSI in HTML

SSI (Server Side Includes) directives let you add dynamically generated content to an HTML page without having to use a CGI program or other dynamic technology to serve the entire page. By default, .html files will not run server-side includes, but .shtml files will. To allow SSI in HTML, you need to add a new handler for HTML.



SSI Handler

To allow SSI, set the Apache handler as 'server-parsed' and the extension as '.html' (without the quotes). This will tell the server to read the .html files so that you may use these directives in them.

Note: Follow these rules:

  • Commands and arguments are in lowercase letters
  • The double quotes around the value are required
  • There is no space until after the command
  • That hash mark (#) is required
  • There is a space after the second double quote, before the second double hyphen (at the end)

Here's the format of the SSI:

<!--#include file="included.html" -->

The above format will create an SSI that will include the text found in the file "included.html".

SSI Format Explained

You use "file=" when the file that will be included is held within the same directory as the file that is calling for it. You can also use the file argument when the file is within a subdirectory of the directory containing the file that is calling for it.

You use the "virtual=" argument if the file you are calling for is located in a position requiring an address starting at the server root. This means the file isn't in the same directory as the page that's calling for it.

Many times, an "includes" directory is set up to contain all of your include files. This is a popular method of doing things. If so, then you'll use the virtual argument to attach the SSI command to the files. Just make a point of giving the command the path from the server root (the domain name). Like so:

<!--#include virtual="/directory/included.html" -->

That forward slash before the first directory is representative of the domain name (server root for that domain).

/home#/username/public_html/ is the server root of the main site of your hosting account (where the username is your cPanel username).

/home#/username/public_html/addondomain/ is the server root to an addon domain of your hosting account.

If you have a file located at /home#/username/public_html/addondomain/includes/includedfile.html that you want to include in http://www.addondomain.com/index.html, then your SSI format inside the index.html file would look like this:

<!--#include virtual="/includes/includedfile.html" -->

By using that leading slash, the server will add the domain name to the front of the address for you.

Rule of Thumb: Use "file=" when the included file is within the same directory as the page that wants it. Use "virtual=" when it isn't.

Note: You need to adjust /home#/ to /home/, /home1/ or home2/ or a different number depending on the home directory your account resides on. To view the home directory for your account, simply view the stats column on the main cPanel page of your account and look for the home directory.

Additional Notes:

By Default, there is an Apache Handler on the server to parse .shtml files which already have server side includes (SSI) inside of them.

Please add this line of code to the .htaccess file to run .shtml includes in a regular HTML file:

  • AddHandler server-parsed .html

Note: SSIs will NOT work until the DNS has propagated to the Bluehost name servers. You will not be able to test them in advance by using something in the format of http://204.130.255.7/~username/test.shtml.

Summary

SSI (Server Side Includes) allows you to add dynamically generated content into HTML pages without having to use CGI programs or other technologies. Note that by default, .html files will not run server-side includes. Discover how to allow SSI in HTML in Apache.

If you need further assistance, feel free to contact us via Chat or Phone:

  • Chat Support - While on our website, you should see a CHAT bubble in the bottom right-hand corner of the page. Click anywhere on the bubble to begin a chat session.
  • Phone Support -
    • US: 888-401-4678
    • International: +1 801-765-9400

You may also refer to our Knowledge Base articles to help answer common questions and guide you through various setup, configuration, and troubleshooting steps.

Did you find this article helpful?

 
* Your feedback is too short

Loading...