Apache's Handler Use
What is a Handler
A "handler" is an internal Apache representation of the action to be
performed when a file is called. Generally, files have implicit
handlers, based on the file type. Normally, all files are simply
served by the server, but certain file typed are "handled"
separately. For example, you may use a type of
"application/x-httpd-cgi" to invoke CGI scripts.
Apache 1.1 adds the additional ability to use handlers
explicitly. Either based on filename extensions or on location, these
handlers are unrelated to file type. This is advantageous both because
it is a more elegant solution, but it also allows for both a type
and a handler to be associated with a file (See also
Files with Multiple Extensions)
Handlers can either be built into the server or to a module, or
they can be added with the Action directive. The built-in
handlers in the standard distribution are as follows:
Send the file using the
default_handler(), which is the
handler used by default to handle static content.
Send file with HTTP headers as is.
Treat the file as a CGI script.
Imagemap rule file.
Get the server's configuration information
Parse for server-side includes
Get the server's status report
Parse as a type map file for content negotiation
Syntax: AddHandler handler-name extension extension...
Context: server config, virtual host, directory, .htaccess
Compatibility: AddHandler is only available in Apache
1.1 and later
AddHandler maps the filename extensions extension to the
handler handler-name. This mapping is added to any already
in force, overriding any mappings that already exist for the same
For example, to activate CGI scripts
with the file extension "
.cgi", you might use:
AddHandler cgi-script cgi
Once that has been put into your srm.conf or httpd.conf file, any
file containing the "
.cgi" extension will be treated as a
See also: Files with
Syntax: SetHandler handler-name
Context: directory, .htaccess
Compatibility: SetHandler is only available in Apache
1.1 and later.
When placed into an
.htaccess file or a
section, this directive forces all matching files to be parsed through
the handler given by handler-name. For example, if you had a
directory you wanted to be parsed entirely as imagemap rule files,
regardless of extension, you might put the following into an
.htaccess file in that directory:
Another example: if you wanted to have the server display a status
report whenever a URL of
called, you might put the following into access.conf:
In order to implement the handler features, an addition has been
made to the Apache API that you may wish to
make use of. Specifically, a new record has been added to the
If you wish to have your module engage a handler, you need only to
r->handler to the name of the handler at any time
prior to the
invoke_handler stage of the
request. Handlers are implemented as they were before, albeit using
the handler name instead of a content type. While it is not
necessary, the naming convention for handlers is to use a
dash-separated word, with no slashes, so as to not invade the media