SSI (Server Side Includes)
From Lunarpages Web Hosting Wiki
How to use SSI in .html pages
Usually you need to use the .shtml extension to utilize Sever Side Includes (SSI) on a server. You can override this behavior in your .htaccess file though.
To configure your site to run .html files that can use Server Side Includes, create a .htaccess file (or edit your current one) and add this to it:
AddType text/html .html AddHandler server-parsed .html
This will tell the server to run .html files using the Server Side Include code that you usually need .shtml files for.
Writing the code
The typical syntax is:
<!--#command argument="value" -->
<!--#include file="file.ext" -->
The command is followed by the argument which is then equal to the value or whatever 'file' represents.
Here are some tips for using SSI:
- Commands and arguments should be in lowercase letters
- The quotes around the value are required
- There is no space until after the command
- The hash mark (#) is required
- There is a space after the second quote, before the second double hyphen (at the end)
- Need to have the file calling the include setup as *.shtml or *.shtm (unless you added the .htaccess code above)
In Example 1 above (<code><!--#include file="file.ext" --></code>) you see that 'file=' was used. This is used when you want to reference a file that is in the same directory as the file calling it. You can also use this method when the file is in a subdirectory of the directory containing the file that is calling it.
There is also the 'virtual' argument.
This is used if the file you are calling is located in a place outside of the directory of the file that is calling it. Perhaps you have a directory where you have all your includes stored.
Virtual can be used to include these. Make a point of giving the command the path from the server root.
<!--#include virtual="/directory/included.html" -->
The forward slash '/' before directory represents the domain name. By using this the server will add the domain name to the front of the address for you. So if you set the virtual variable to "/includes/ssi/example.html" the browser would pull up http://yourdomain.com/includes/ssi/example.html.
So you would use file= when the included file is within the same directory as the page that calls it, and virtual= when it is not.
Using .txt - .html - .htm
You can include simple text (.txt) files, or .html/.htm files.
If you give the include file a .html or .htm extension, please note that even though the file has that extension it is not required to be a fully formed html document. If you want only 1 line of text, that's all you need. If you include the title, and body tags etc, all of this would be included in the SSI and that is something you might not want.
Only use what you need in the file you are including, no matter how bare it looks, it will be included in a fully formed document.
You can also use the following in *.shtml and *.shtm files:
<!--#echo var="DATE_GMT" --> // Returns Greenwich Mean Time from the server. <!--#echo var="Document_Name" --> // Returns the name of the document. <!--#echo var="Document_URI" --> // Returns the path to the document plus its name. <!--#echo var="Last_Modified" --> // Returns when the document was last posted to the server.
FLASTMOD Command: (Basically 'File Last Modified') Similar to the ECHO command for "Last Modified", however, it allows you to see the last modified date on a specific page, whereas the ECHO command is specific to the document that line is included in. Either of these should work:
<!--#flastmod file="file.html" --> <!--#flastmod file="/path/to/page.html" -->
FSIZE Command: Allows you to display the File size of a page, like the FLASTMOD command allowed you to display the last modified date on a document. The syntax for this is:
<!--#fsize file="page.html" -->
If you require additional assistance, or have any other inquiries about SSI and Lunarpages please email us at firstname.lastname@example.org and we'll be happy to assist you.