8.7. Server-Side Inclusion
The more powerful method is server-side inclusion (SSI). It allows you to parse the feed using any technique and any language you like, and it allows greater flexibility for how the feed is used.
Let's look at an example of how it works. Example 8-10 produces an XHTML page with a server-side include directive.
Example 8-10. An XHTML page with a server-side include
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>An Example of a SSI</title> </head> <body> <h1>This here is a News Feed from a really good site</h1> <!--#include file="parsedfeed.html" --> </body> </html>
A server serving the page in Example 8-10 will, if the server is set up correctly, import the contents of parsedfeed.html and insert them in place of the SSI directive <!-- #include file="parsedfile.html" -->.
So, by parsing RSS files into XHTML and saving them to disk, you can use SSI to place them within an existing XHTML page, apply formatting to change the way they look via the site's CSS stylesheet, and present them to the end user.
8.7.1. Enabling Server-Side Includes Within Apache 1.3.x
Turning on server-side includes within Apache is straightforward, but it involves delving into places where a wrong move can make a nasty mess. Have a coffee, then concentrate.
To permit SSI on your server, you must have the following directive either in your httpd.conf file or in a .htaccess file:
This tells Apache you want to permit files to be parsed for SSI directives. Of course, real-world installations are more complicated than that; most Apache installations have multiple Options directives set: one for each directory in some cases. You will most likely want to apply the Options to the specific directory in which you want SSI enabledwhere the document in which you want to include the RSS feeds resides.
Example 8-11 shows the relevant section of the httpd.conf file for my own server.
Example 8-11. A section of an Apache http.conf file that allows for CGI and SSI
<Directory "/usr/local/apache/htdocs/rss"> Options ExecCGI Includes DirectoryIndex index.shtml </Directory>
Note that this configuration defines the directory's index page as index.shtml because it isn't a good idea to make your browser seek out SSI directives in every page it serves. Rather, you should tell it to look for SSI directives solely in pages that end with a certain file extension by adding the following lines to your httpd.conf file
AddType text/html .shtml AddHandler server-parsed .shtml
This makes Apache search any file ending in .shtml (the traditional extension for such things) for SSI directives and replace them with their associated files before serving them to the end user.
This approach has a disadvantage: if you want to add SSI directives to an existing page, you have to change the name of that page. All links to that page will therefore be broken in order to get the SSI directives to work. So, if you're retrofitting a site with RSS, the other method is to use the XBitHack directive within your httpd.conf file:
XBitHack tells Apache to parse files for SSI directives if the files have the execute bit set. So, to add SSI directives to an existing page, rather than having to change the filename, you just need to make the file executable using chmod.
8.7.2. Server-Side Includes with Microsoft IIS
Microsoft's Internet Information Services (IIS) server package comes with server-side includes enabled: by default, it processes any file ending in .stm, .shtm, or .shtml. However, files are processed only if they're inside directories with Scripts or Execute access permissions.
Here's how to set these permissions: