|
Server Side IncludesThe often maligned, Server Side Include can actually be very helpful in managing common page sections. Using somewhat obscure techniques you can even use SSI to control page areas that feature variable content. Useful for
Common complaints
Rebuttal
SSI lets you embed a number of special 'commands' into the HTML such as displaying when a file was last modified, inserting another HTML file, or echoing a string of characters when an 'if' expression is true. The most common use for SSI is to have the same footer display on every page. The footer is a separate file that gets pulled in by the server when a browser requests a web page with an included footer. We will use this page as an example. To create an included footer, create an HTML file called footer.html with the footer information you want. To insert this footer into your page, add the following code at the end of the document
Then name your page with the extension .shtml instead of .html or .htm. To see your file with the footer included, view the .shtml file in a browser. If you name a file index.shtml in a directory, and no index.html is present, index.shtml will load as the default page for that directory. The syntax is similar for other includes. XBitHackBy default any file with the extension .shtml will be processed as a file that contains SSI instructions. The main MIT web servers (http://web.mit.edu/) have the Apache XBitHack directive enabled. This directive allows content providers to specify using UNIX file permissions which files should be parsed for SSI —regardless of the file extension. If you have a file, index.html that has SSI instructions in it you can enable SSI processing with out changing the file extension by executing the folowing statement via the Athena command line interface: athena:~ www$ chmod 755 index.html
Processing all files in a directory structure as SSI filesThere is a way to process your files as SSI files without using the .shtml extension. To have all .html files in a particular directory structure parsed for server side include instructions, you can place a .htaccess.mit file at the top-most Athena directory of your choosing. This file (which may also contain instructions for securing content via MIT certificates or instructions for creating a custom 404 error page) must contain the following line: AddHandler server-parsed .html You can change .html to any file extension (i.e. .htm) as long as they are files intended to be processed as if they were .shtml. Other options that are available with the include module on web.mit.edu:
The "exec" feature of server-side includes is disabled, so you can't run scripts or commands from them. The following common environment variables can be used in #if and #echo statements, e.g. DOCUMENT_ROOT The full list of variables you can use for the #if and #echo
commands is available from ssi-echo.shtml. More information about
server side includes is available from Apache Week and Apache.org. |
| Home | Getting Started | Getting Services | Getting Help | About IS&T | Accessibility Ask a technology question or send a comment about this web page. |
||