SSI commands are handled by the mod_include module, which comes with the standard Apache distribution. [6] The mod_include filter is controlled by special SGML directives that allow conditional includes of files or programs. You can set, check, and print environment variables to sniff browsers or perform time-based tasks . (You can skip the next section if you don't have access to Apache configuration files.)
Here are some ways you can speed up mod_include:
Consider XBitHack or .shtml .
Run mod_include per virtual server.
Use AllowOverride None to avoid .htaccess queries.
Enable caching with XBitHack Full or mod_expires.
To tell Apache which files to parse for SSI commands, you can use .shtml and .html suffixes:
# To use server-parsed HTML files AddType text/html .html AddType text/html .shtml AddHandler server-parsed shtml AddHandler server-parsed html
However, telling Apache to parse all .html files for SSI is inefficient. Using .shtml or XBitHack to parse only files with the execute bit set to On is more efficient, as you see here:
<VirtualHost xxx.xx.xx.xx> DocumentRoot /www/webref/webref ServerName www.webreference.com ErrorDocument 404 /_404.html DirectoryIndex index.html index.shtml index.wml XBitHack On </VirtualHost>
To enable includes, you use the Options Includes directive. You can either place this directive in the root directory section, which enables includes for the entire server, or you can place it within a Virtual Host section with a Directory entry for speed:
<Directory /www/webref/webref> Options FollowSymlinks Includes Options IncludesNOEXEC order deny,allow deny from all </Directory>
Note that we use the IncludesNOEXEC version, which closes a possible security hole.
The AllowOverride directive controls how the .htaccess files work, one per directory. By using the httpd.conf file, we can ignore .htaccess files and speed up the server. Without this directive, Apache traverses the directory tree above the requested resource, looking for .htaccess directives that apply, slowing down each request:
<Directory /> AllowOverride None Options FollowSymLinks order deny,allow deny from all </Directory>
By default, Apache does not send the last modified date for SSI pages, which can prevent your pages from being cached. There are two solutions, XBitHack Full , and mod_expires. XBitHack Full sends the last modified date of the original file, ignoring any included files. mod_expires allows you to set expiration times for your files, allowing them to be cached. For more details, see the Apache documentation. [7]
Now that you've got your server tuned to run SSI, let's look at some more advanced ways to use SSI. Besides creating SSI templates and nested includes, you can perform browser sniffing with SSI to include conditional code.