]> granicus.if.org Git - apache/blob - docs/manual/custom-error.html
Another massive sweep, adding SSI header/footer combos.
[apache] / docs / manual / custom-error.html
1 <HTML>
2 <HEAD>
3 <TITLE>Ccustom error responses</TITLE>
4 </HEAD>
5
6 <BODY>
7 <!--#include virtual="header.html" -->
8 <H1>Custom error responses</H1>
9
10 <DL>
11 <DT>Purpose
12 <DD>Additional functionality. Allows webmasters to configure the response of
13 Apache to some error or problem.<BR>
14 <P>Customizable responses can be defined to be activated in the event of a
15 server detected error or problem.<BR>
16 e.g. if a script crashes and produces a "500 Server Error" response, then
17 this response can be replaced with either some friendlier text or by a
18 redirection to another URL (local or external).
19 <DT>Old behavior
20 <DD>NCSA httpd 1.3 would return some boring old error/problem message which
21 would often be meaningless to the user, and would provide no means of logging
22 the symptoms which caused it.<BR><BR>
23 <DT>New behavior
24 <DD>The server can be asked to;
25 <OL>
26 <LI>Display some other text, instead of the NCSA hard coded messages, or
27 <LI>redirect to a local URL, or
28 <LI>redirect to an external URL.
29 </OL>
30 <P>Redirecting to another URL can be useful, but only if some information
31 can be passed which can then be used to explain and/or log the error/problem
32 more clearly.<BR>To achieve this, Apache will define new CGI-like environment
33 variables, e.g.
34 <blockquote><code>
35 REDIRECT_HTTP_ACCEPT=*/*, image/gif, image/x-xbitmap, image/jpeg <br>
36 REDIRECT_HTTP_USER_AGENT=Mozilla/1.1b2 (X11; I; HP-UX A.09.05 9000/712) <br>
37 REDIRECT_PATH=.:/bin:/usr/local/bin:/etc <br>
38 REDIRECT_QUERY_STRING= <br>
39 REDIRECT_REMOTE_ADDR=121.345.78.123 <br>
40 REDIRECT_REMOTE_HOST=ooh.ahhh.com <br>
41 REDIRECT_SERVER_NAME=crash.bang.edu <br>
42 REDIRECT_SERVER_PORT=80 <br>
43 REDIRECT_SERVER_SOFTWARE=Apache/0.8.15 <br>
44 REDIRECT_URL=/cgi-bin/buggy.pl <br>
45 </code></blockquote>
46
47 note the <code>REDIRECT_</code> prefix. <p>
48
49 At least <code>REDIRECT_URL</code> and <code>REDIRECT_QUERY_STRING</code> will
50 be passed to the new URL (assuming it's a cgi-script or a cgi-include). The
51 other variables will exist only if they existed prior to the error/problem.<p>
52
53 <DT>Configuration
54 <DD><em>file: </em>server configuration<BR>
55 <P>Here are some examples...
56 <blockquote><code>
57 ErrorDocument 500 /cgi-bin/crash-recover <br>
58 ErrorDocument 500 "Sorry, our script crashed because %s. Oh dear<br>
59 ErrorDocument 500 http://xxx/ <br>
60 ErrorDocument 404 /Lame_excuses/not_found.html  <br>
61 ErrorDocument 401 /Subscription/how_to_subscribe.html
62 </code></blockquote>
63 The syntax is, <p>
64 <code><A HREF="core.html#errordocument">ErrorDocument</A></code>
65 &lt;3-digit-code&gt; action <p>
66
67 where the action can be,
68 <OL>
69 <LI>Text to be displayed.<BR>Prefix the text with a quote (&quot;). Whatever
70 follows the quote is displayed. If the error/problem produced any additional
71 information, it can be specified using <code>%s</code>.
72 <em>Note: the (&quot;) prefix isn't displayed.</em>
73 <LI>An external URL to redirect to.
74 <LI>A local URL to redirect to.
75 </OL>
76 <P><code>ErrorDocument</code> definitions are sensitive to a
77 <code>SIGHUP</code>, so you can change any of the definitions or add new ones
78 prior to sending a <code>SIGHUP</code> (kill -1) signal.
79 </DL>
80 <P><HR><P>
81
82 <h2>Custom error responses and redirects</H2>
83 <DL>
84 <DT>Purpose
85 <DD>Apache's behaviour to redirected URLs has been modified so that additional
86 environment variables are available to a script/server-include.<p>
87
88 <DT>Old behaviour
89 <DD>Standard CGI vars were made available to a script which has been
90 redirected to. No indication of where the redirection came from was provided.
91 <p>
92 <DT>New behaviour
93 <DD>A new batch of environment variables will be initialized for use by a
94 script which has been redirected to.<BR>
95 Each new variable will have the prefix <code>REDIRECT_</code>.<BR>
96 REDIRECT_ environment variables are created from the CGI environment
97 variables which existed prior to the redirect, they are renamed with a
98 REDIRECT_ prefix, i.e. HTTP_USER_AGENT -&gt; REDIRECT_HTTP_USER_AGENT.<BR>
99 In addition to these new variables, Apache will define
100 <code>REDIRECT_URL</code> and <code>REDIRECT_STATUS</code> to help the script
101 trace its origin.<BR>
102 Logging: both the original URL and the URL being redirected to, will
103 now be logged correctly in the access log.<p>
104 </DL>
105
106 <!--#include virtual="footer.html" -->
107 </BODY>
108 </HTML>