Section 8.7. Server-Side Inclusion


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.

This section discusses Apache Version 1.3.x. Apache's configuration structure may change in later versions. Consult the documentation online at http://www.apache.org.


To permit SSI on your server, you must have the following directive either in your httpd.conf file or in a .htaccess file:

Options +Includes

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 on

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.

How Often to Read the Feed

Feeds do change, it is true. People update their sites at all hours, and it would be lovely to have the very latest headlines. Currently, however, it isn't a good idea to keep requesting a new feed every few minutes. Etiquette and convention limit requests for a new file to once every 60 minutes, unless the feed's publisher specifically allows you to grab it more often, or unless said publisher is using Publish and Subscribe (see Chapter 9).

In many cases, even requesting the feed every hour is too much. Feeds that change only once a day require downloading only once a day. It's a simple courtesy to pay attention to these conventions.


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:

  1. Open My Computer, select the directory in which you want to allow SSI, and right-click to open its property menu.

  2. On the Security property menu, select the Windows account for which you want to change permissions.

  3. Under Permissions, select the types of access for the selected user or group. Use Allow to specifically allow access and Deny to specifically deny access. For more choices, click Advanced.



    Developing Feeds with RSS and Atom
    Developing Feeds with Rss and Atom
    ISBN: 0596008813
    EAN: 2147483647
    Year: 2003
    Pages: 118

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net