SSI with Apache

<!--#set var="footer" value="I agree :-)" -->

What are SSI?

SSI (Server Side Includes) are directives that are placed in HTML pages, and evaluated on the server while the pages are being served. They let you add dynamically generated content to an existing HTML page, without having to serve the entire page via a CGI program, or other dynamic technology.

The decision of when to use SSI, and when to have your page entirely generated by some program, is usually a matter of how much of the page is static, and how much needs to be recalculated every time the page is served. SSI is a great way to add small pieces of information, such as the current time. But if a majority of your page is being generated at the time that it is served, you need to look for some other solution.

http://httpd.apache.org/docs/howto/ssi.html.en#whataressi

Enabling SSI with .htaccess

Options +Includes
AddType text/html .shtml
AddHandler server-parsed .shtml

Some examples

All text inserted with SSI is green (<ins>).

<!--#echo var="DATE_LOCAL" -->
It's now Wednesday, 23-May-2012 21:50:32 W. Europe Daylight Time
<!--#config timefmt="%d-%m-%Y" -->
<!--#echo var="DATE_LOCAL" -->
Today it's 23-05-2012
<!--#config timefmt="On %d-%m-%Y at %H:%M:%I hour" -->
<!--#flastmod file="index.shtml" -->
or <!--#echo var="LAST_MODIFIED" -->
On 23-11-2006 at 11:23:11 hour this file was modified for the last time. (On 23-11-2006 at 11:23:11 hour)
<!--#exec cmd="nslookup krijnhoetmer.nl" -->
Server: 192.168.2.254 Address: 192.168.2.254 Name: krijnhoetmer.nl Address: 145.53.238.157
<!--#set var="myName" value="Krijn Hoetmer" -->
<!--#echo var="myName" -->
Krijn Hoetmer
<!--#config timefmt="%H" -->
<!--#if expr="${DATE_LOCAL} > 18" -->
It's evening at my computer now.
<!--#elif expr="${DATE_LOCAL} > 12" -->
It's afternoon at my computer now.
<!--#elif expr="${DATE_LOCAL} > 6" -->
It's morning at my computer now.
<!--#elif expr="${DATE_LOCAL} > 0" -->
It's night at my computer now.
<!--#endif -->
It's evening at my computer now.
<!--#include file="include.html" -->
This is an included part, inside include.html

Conclusion

SSI is certainly not a replacement for CGI, or other technologies used for generating dynamic web pages. But it is a great way to add small amounts of dynamic content to pages, without doing a lot of extra work.

http://httpd.apache.org/docs/howto/ssi.html.en#conclusion

I agree :-)


Home - More stuff