4.9. Actions
A related notion to that of handlers is actions. An action passes specified files through a named CGI script before they are served up.
4.9.1. Action
Action type cgi_script Server config, virtual host, directory, .htaccess
The cgi_script is applied to any file of MIME or handler type matching type whenever it is requested. This mechanism can be used in a number of ways. For instance, it can be handy to put certain files through a filter before they are served up on the Web. As a simple example, suppose we wanted to keep all our .html files in compressed format to save space, and to uncompress them on the fly as they are retrieved. Apache happily does this. We make site.filter a copy of site.firs t, except that the httpd.conf file is as follows:
User webuser Group webgroup ServerName localhost DocumentRoot /usr/www/site.filter/htdocs ScriptAlias /cgi-bin /usr/www/cgi-bin AccessConfig /dev/null ResourceConfig /dev/null AddHandler peter-zipped-html zhtml Action peter-zipped-html /cgi-bin/unziphtml <Directory /usr/www/site.filter/htdocs> DirectoryIndex index.zhtml </Directory>
The points to notice are that:
AddHandler sets up a new handler with a name we invented, peter-zipped-html, and associates a file extension with it: zhtml (notice the absence of the period).
Action sets up a filter. For instance:
Action peter-zipped-html /cgi-bin/unziphtml
means "apply the CGI script unziphtml to anything with the handler name peter-zipped-html."
The CGI script ... /cgi-bin/unziphtml ...
Get Apache: The Definitive Guide, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.