1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
4 <TITLE>Apache's Handler Use</TITLE>
7 <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
15 <!--#include virtual="header.html" -->
16 <H1 ALIGN="CENTER">Apache's Handler Use</H1>
18 <H2>What is a Handler</H2>
20 <P>A "handler" is an internal Apache representation of the action to be
21 performed when a file is called. Generally, files have implicit
22 handlers, based on the file type. Normally, all files are simply
23 served by the server, but certain file typed are "handled"
24 separately. For example, you may use a type of
25 "application/x-httpd-cgi" to invoke CGI scripts.</P>
27 <P>Apache 1.1 adds the additional ability to use handlers
28 explicitly. Either based on filename extensions or on location, these
29 handlers are unrelated to file type. This is advantageous both because
30 it is a more elegant solution, but it also allows for both a type
31 <STRONG>and</STRONG> a handler to be associated with a file (See also
32 <A HREF="mod/mod_mime.html#multipleext">Files with Multiple Extensions</A>)
36 <P>Handlers can either be built into the server or to a module, or
37 they can be added with the <A
38 HREF="mod/mod_actions.html#action">Action</A> directive. The built-in
39 handlers in the standard distribution are as follows:</P>
42 <LI><STRONG>default-handler</STRONG>:
43 Send the file using the <CODE>default_handler()</CODE>, which is the
44 handler used by default to handle static content.
46 <LI><STRONG>send-as-is</STRONG>:
47 Send file with HTTP headers as is.
48 (<A HREF="mod/mod_asis.html">mod_asis</A>)
49 <LI><STRONG>cgi-script</STRONG>:
50 Treat the file as a CGI script.
51 (<A HREF="mod/mod_cgi.html">mod_cgi</A>)
52 <LI><STRONG>imap-file</STRONG>:
54 (<A HREF="mod/mod_imap.html">mod_imap</A>)
55 <LI><STRONG>server-info</STRONG>:
56 Get the server's configuration information
57 (<A HREF="mod/mod_info.html">mod_info</A>)
58 <LI><STRONG>server-parsed</STRONG>:
59 Parse for server-side includes
60 (<A HREF="mod/mod_include.html">mod_include</A>)
61 <LI><STRONG>server-status</STRONG>:
62 Get the server's status report
63 (<A HREF="mod/mod_status.html">mod_status</A>)
64 <LI><STRONG>type-map</STRONG>:
65 Parse as a type map file for content negotiation
66 (<A HREF="mod/mod_negotiation.html">mod_negotiation</A>)
73 <LI><A HREF="#addhandler">AddHandler</A>
74 <LI><A HREF="#sethandler">SetHandler</A>
79 <H2><A NAME="addhandler">AddHandler</A></H2>
82 HREF="mod/directive-dict.html#Syntax"
84 ><STRONG>Syntax:</STRONG></A> AddHandler <EM>handler-name extension extension...</EM><BR>
86 HREF="mod/directive-dict.html#Context"
88 ><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
90 HREF="mod/directive-dict.html#Override"
92 ><STRONG>Override:</STRONG></A> FileInfo<BR>
94 HREF="mod/directive-dict.html#Status"
96 ><STRONG>Status:</STRONG></A> Base<BR>
98 HREF="mod/directive-dict.html#Module"
100 ><STRONG>Module:</STRONG></A> mod_mime<BR>
102 HREF="mod/directive-dict.html#Compatibility"
104 ><STRONG>Compatibility:</STRONG></A> AddHandler is only available in Apache
107 <P>AddHandler maps the filename extensions <EM>extension</EM> to the
108 handler <EM>handler-name</EM>. This mapping is added to any already
109 in force, overriding any mappings that already exist for the same
112 For example, to activate CGI scripts
113 with the file extension "<CODE>.cgi</CODE>", you might use:
115 AddHandler cgi-script cgi
118 <P>Once that has been put into your srm.conf or httpd.conf file, any
119 file containing the "<CODE>.cgi</CODE>" extension will be treated as a
124 <STRONG>See also</STRONG>: <A HREF="mod/mod_mime.html#multipleext">Files with
125 multiple extensions</A>
129 <H2><A NAME="sethandler">SetHandler</A></H2>
132 HREF="mod/directive-dict.html#Syntax"
134 ><STRONG>Syntax:</STRONG></A> SetHandler <EM>handler-name</EM><BR>
136 HREF="mod/directive-dict.html#Context"
138 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
140 HREF="mod/directive-dict.html#Status"
142 ><STRONG>Status:</STRONG></A> Base<BR>
144 HREF="mod/directive-dict.html#Module"
146 ><STRONG>Module:</STRONG></A> mod_mime<BR>
148 HREF="mod/directive-dict.html#Compatibility"
150 ><STRONG>Compatibility:</STRONG></A> SetHandler is only available in Apache
153 <P>When placed into an <CODE>.htaccess</CODE> file or a
154 <CODE><Directory></CODE> or <CODE><Location></CODE>
155 section, this directive forces all matching files to be parsed through
156 the handler given by <EM>handler-name</EM>. For example, if you had a
157 directory you wanted to be parsed entirely as imagemap rule files,
158 regardless of extension, you might put the following into an
159 <CODE>.htaccess</CODE> file in that directory:
164 <P>Another example: if you wanted to have the server display a status
165 report whenever a URL of <CODE>http://servername/status</CODE> was
166 called, you might put the following into access.conf:
168 <Location /status>
169 SetHandler server-status
174 <H2>Programmer's Note</H2>
176 <P>In order to implement the handler features, an addition has been
177 made to the <A HREF="misc/API.html">Apache API</A> that you may wish to
178 make use of. Specifically, a new record has been added to the
179 <CODE>request_rec</CODE> structure:</P>
183 <P>If you wish to have your module engage a handler, you need only to
184 set <CODE>r->handler</CODE> to the name of the handler at any time
185 prior to the <CODE>invoke_handler</CODE> stage of the
186 request. Handlers are implemented as they were before, albeit using
187 the handler name instead of a content type. While it is not
188 necessary, the naming convention for handlers is to use a
189 dash-separated word, with no slashes, so as to not invade the media
192 <!--#include virtual="footer.html" -->