You know the story, you’ve inherited a lovely design and XHTML page build from your designer. The pages are modular and built using server side includes (SSI). The site is easy to update, until you’re asked to make something dynamic.
Normally, I’d use Perl‘s excellent Template Toolkit, and just convert the SSIs to Template Toolkit INCLUDEs. However in this case, the SSIs were nested so I couldn’t take this approach.
The solution turns out to be quite easy, especially as I’m using Apache 2 as my webserver.
Apache 2 has output filters, so I can get the output of my CGI scripts to be parsed by Apache for SSIs directly using mod_include.
In my apache conf file, I need to do something like the following.
<Location /cgi-bin/withssi/>
SetHandler cgi-script
SetOutputFilter INCLUDES
Options +ExecCGI +Includes
</Location>
This will turn on SSI parsing on the output of CGI scripts served from the location of /cgi-bin/withssi.
The key line to notice here is SetOutputFilter INCLUDES as that makes sure the output returned is parsed by mod_include before it reaches the web browser.