1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
6<html xmlns="http://www.w3.org/1999/xhtml">
7  <head>
8    <meta name="generator" content="HTML Tidy, see www.w3.org" />
9
10    <title>Custom error responses</title>
11  </head>
12  <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
13
14  <body bgcolor="#FFFFFF" text="#000000" link="#0000FF"
15  vlink="#000080" alink="#FF0000">
16        <div align="CENTER">
17      <img src="images/sub.gif" alt="[APACHE DOCUMENTATION]" />
18
19      <h3>Apache HTTP Server</h3>
20    </div>
21
22
23
24    <h1 align="CENTER">Custom error responses</h1>
25
26    <dl>
27      <dt>Purpose</dt>
28
29      <dd>
30        Additional functionality. Allows webmasters to configure
31        the response of Apache to some error or problem.
32
33        <p>Customizable responses can be defined to be activated in
34        the event of a server detected error or problem.</p>
35
36        <p>e.g. if a script crashes and produces a "500 Server
37        Error" response, then this response can be replaced with
38        either some friendlier text or by a redirection to another
39        URL (local or external).</p>
40      </dd>
41
42      <dt>Old behavior</dt>
43
44      <dd>NCSA httpd 1.3 would return some boring old error/problem
45      message which would often be meaningless to the user, and
46      would provide no means of logging the symptoms which caused
47      it.<br />
48      </dd>
49
50      <dt>New behavior</dt>
51
52      <dd>
53        The server can be asked to;
54
55        <ol>
56          <li>Display some other text, instead of the NCSA hard
57          coded messages, or</li>
58
59          <li>redirect to a local URL, or</li>
60
61          <li>redirect to an external URL.</li>
62        </ol>
63
64        <p>Redirecting to another URL can be useful, but only if
65        some information can be passed which can then be used to
66        explain and/or log the error/problem more clearly.</p>
67
68        <p>To achieve this, Apache will define new CGI-like
69        environment variables, <em>e.g.</em></p>
70
71        <blockquote>
72          <code>REDIRECT_HTTP_ACCEPT=*/*, image/gif,
73          image/x-xbitmap, image/jpeg<br />
74           REDIRECT_HTTP_USER_AGENT=Mozilla/1.1b2 (X11; I; HP-UX
75          A.09.05 9000/712)<br />
76           REDIRECT_PATH=.:/bin:/usr/local/bin:/etc<br />
77           REDIRECT_QUERY_STRING=<br />
78           REDIRECT_REMOTE_ADDR=121.345.78.123<br />
79           REDIRECT_REMOTE_HOST=ooh.ahhh.com<br />
80           REDIRECT_SERVER_NAME=crash.bang.edu<br />
81           REDIRECT_SERVER_PORT=80<br />
82           REDIRECT_SERVER_SOFTWARE=Apache/0.8.15<br />
83           REDIRECT_URL=/cgi-bin/buggy.pl<br />
84          </code>
85        </blockquote>
86
87        <p>note the <code>REDIRECT_</code> prefix.</p>
88
89        <p>At least <code>REDIRECT_URL</code> and
90        <code>REDIRECT_QUERY_STRING</code> will be passed to the
91        new URL (assuming it's a cgi-script or a cgi-include). The
92        other variables will exist only if they existed prior to
93        the error/problem. <strong>None</strong> of these will be
94        set if your ErrorDocument is an <em>external</em> redirect
95        (<em>i.e.</em>, anything starting with a scheme name like
96        <code>http:</code>, even if it refers to the same host as
97        the server).</p>
98      </dd>
99
100      <dt>Configuration</dt>
101
102      <dd>
103        Use of "ErrorDocument" is enabled for .htaccess files when
104        the <a href="mod/core.html#allowoverride">"FileInfo"
105        override</a> is allowed.
106
107        <p>Here are some examples...</p>
108
109        <blockquote>
110          <code>ErrorDocument 500 /cgi-bin/crash-recover<br />
111           ErrorDocument 500 "Sorry, our script crashed. Oh
112          dear<br />
113           ErrorDocument 500 http://xxx/<br />
114           ErrorDocument 404 /Lame_excuses/not_found.html<br />
115           ErrorDocument 401
116          /Subscription/how_to_subscribe.html</code>
117        </blockquote>
118
119        <p>The syntax is,</p>
120
121        <p><code><a
122        href="mod/core.html#errordocument">ErrorDocument</a></code>
123        &lt;3-digit-code&gt; action</p>
124
125        <p>where the action can be,</p>
126
127        <ol>
128          <li>Text to be displayed. Prefix the text with a quote
129          ("). Whatever follows the quote is displayed. <em>Note:
130          the (") prefix isn't displayed.</em></li>
131
132          <li>An external URL to redirect to.</li>
133
134          <li>A local URL to redirect to.</li>
135        </ol>
136      </dd>
137    </dl>
138    <hr />
139
140    <h2>Custom error responses and redirects</h2>
141
142    <dl>
143      <dt>Purpose</dt>
144
145      <dd>Apache's behavior to redirected URLs has been modified so
146      that additional environment variables are available to a
147      script/server-include.</dd>
148
149      <dt>Old behavior</dt>
150
151      <dd>Standard CGI vars were made available to a script which
152      has been redirected to. No indication of where the
153      redirection came from was provided.</dd>
154
155      <dt>New behavior</dt>
156
157      <dd>A new batch of environment variables will be initialized
158      for use by a script which has been redirected to. Each new
159      variable will have the prefix <code>REDIRECT_</code>.
160      <code>REDIRECT_</code> environment variables are created from
161      the CGI environment variables which existed prior to the
162      redirect, they are renamed with a <code>REDIRECT_</code>
163      prefix, <em>i.e.</em>, <code>HTTP_USER_AGENT</code> becomes
164      <code>REDIRECT_HTTP_USER_AGENT</code>. In addition to these
165      new variables, Apache will define <code>REDIRECT_URL</code>
166      and <code>REDIRECT_STATUS</code> to help the script trace its
167      origin. Both the original URL and the URL being redirected to
168      can be logged in the access log.</dd>
169    </dl>
170
171    <p>If the ErrorDocument specifies a local redirect to a CGI
172    script, the script should include a "<samp>Status:</samp>"
173    header field in its output in order to ensure the propagation
174    all the way back to the client of the error condition that
175    caused it to be invoked. For instance, a Perl ErrorDocument
176    script might include the following:</p>
177<pre>
178      :
179    print  "Content-type: text/html\n";
180    printf "Status: %s Condition Intercepted\n", $ENV{"REDIRECT_STATUS"};
181      :
182</pre>
183
184    <p>If the script is dedicated to handling a particular error
185    condition, such as <samp>404&nbsp;Not&nbsp;Found</samp>, it can
186    use the specific code and error text instead.</p>
187        <hr />
188
189    <h3 align="CENTER">Apache HTTP Server</h3>
190    <a href="./"><img src="images/index.gif" alt="Index" /></a>
191
192  </body>
193</html>
194
195
196
197