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 decompress them on the fly as
they are retrieved. Apache happily does this. We make
site.filter a copy of
site.first, except that the
httpd.conf file is as follows:
User webuser
Group webgroup
ServerName localhost
DocumentRoot /usr/www/APACHE3/site.filter/htdocs
ScriptAlias /cgi-bin /usr/www/APACHE3/cgi-bin
AccessConfig /dev/null
ResourceConfig /dev/null
AddHandler peter-zipped-html zhtml
Action peter-zipped-html /cgi-bin/unziphtml
<Directory /usr/www/APACHE3/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 contains
the following:
#!/bin/sh
echo "Content-Type: text/html"
echo
gzip -S .zhtml -d -c $PATH_TRANSLATED
This applies gzip with the following flags:
- -S
-
Sets the file extension as .zhtml
- -d
-
Uncompresses the file
- -c
-
Outputs the results to the standard output so they get sent to the
client, rather than decompressing in place
gzip is applied to the file contained in the
environment variable PATH_TRANSLATED.
Finally, we have to turn our .htmls into
.zhtmls. In ... /htdocs we
have compressed and renamed: