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