custom-error.html revision 57d0156f7bbd9ea3a72342cf9912aba61d118702
e07d9cb85217949d497b02d7211de8a197d2f2ebzf<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
fb91fd8a302dfb13e250bbefb6a3970c2edc3ae3zf "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf<html xmlns="http://www.w3.org/1999/xhtml">
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <head>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <meta name="generator" content="HTML Tidy, see www.w3.org" />
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <title>Custom error responses</title>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf </head>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <body bgcolor="#FFFFFF" text="#000000" link="#0000FF"
e07d9cb85217949d497b02d7211de8a197d2f2ebzf vlink="#000080" alink="#FF0000">
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <!--#include virtual="header.html" -->
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <h1 align="CENTER">Custom error responses</h1>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <dl>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <dt>Purpose</dt>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <dd>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf Additional functionality. Allows webmasters to configure
e07d9cb85217949d497b02d7211de8a197d2f2ebzf the response of Apache to some error or problem.
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <p>Customizable responses can be defined to be activated in
e07d9cb85217949d497b02d7211de8a197d2f2ebzf the event of a server detected error or problem.</p>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <p>e.g. if a script crashes and produces a "500 Server
e07d9cb85217949d497b02d7211de8a197d2f2ebzf Error" response, then this response can be replaced with
e07d9cb85217949d497b02d7211de8a197d2f2ebzf either some friendlier text or by a redirection to another
e07d9cb85217949d497b02d7211de8a197d2f2ebzf URL (local or external).</p>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf </dd>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <dt>Old behavior</dt>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <dd>NCSA httpd 1.3 would return some boring old error/problem
e07d9cb85217949d497b02d7211de8a197d2f2ebzf message which would often be meaningless to the user, and
e07d9cb85217949d497b02d7211de8a197d2f2ebzf would provide no means of logging the symptoms which caused
e07d9cb85217949d497b02d7211de8a197d2f2ebzf it.<br />
e07d9cb85217949d497b02d7211de8a197d2f2ebzf </dd>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <dt>New behavior</dt>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <dd>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf The server can be asked to;
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <ol>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <li>Display some other text, instead of the NCSA hard
e07d9cb85217949d497b02d7211de8a197d2f2ebzf coded messages, or</li>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <li>redirect to a local URL, or</li>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <li>redirect to an external URL.</li>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf </ol>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <p>Redirecting to another URL can be useful, but only if
e07d9cb85217949d497b02d7211de8a197d2f2ebzf some information can be passed which can then be used to
e07d9cb85217949d497b02d7211de8a197d2f2ebzf explain and/or log the error/problem more clearly.</p>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <p>To achieve this, Apache will define new CGI-like
e07d9cb85217949d497b02d7211de8a197d2f2ebzf environment variables, <em>e.g.</em></p>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <blockquote>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <code>REDIRECT_HTTP_ACCEPT=*/*, image/gif,
e07d9cb85217949d497b02d7211de8a197d2f2ebzf image/x-xbitmap, image/jpeg<br />
e07d9cb85217949d497b02d7211de8a197d2f2ebzf REDIRECT_HTTP_USER_AGENT=Mozilla/1.1b2 (X11; I; HP-UX
e07d9cb85217949d497b02d7211de8a197d2f2ebzf A.09.05 9000/712)<br />
e07d9cb85217949d497b02d7211de8a197d2f2ebzf REDIRECT_PATH=.:/bin:/usr/local/bin:/etc<br />
e07d9cb85217949d497b02d7211de8a197d2f2ebzf REDIRECT_QUERY_STRING=<br />
e07d9cb85217949d497b02d7211de8a197d2f2ebzf REDIRECT_REMOTE_ADDR=121.345.78.123<br />
e07d9cb85217949d497b02d7211de8a197d2f2ebzf REDIRECT_REMOTE_HOST=ooh.ahhh.com<br />
e07d9cb85217949d497b02d7211de8a197d2f2ebzf REDIRECT_SERVER_NAME=crash.bang.edu<br />
e07d9cb85217949d497b02d7211de8a197d2f2ebzf REDIRECT_SERVER_PORT=80<br />
e07d9cb85217949d497b02d7211de8a197d2f2ebzf REDIRECT_SERVER_SOFTWARE=Apache/0.8.15<br />
e07d9cb85217949d497b02d7211de8a197d2f2ebzf REDIRECT_URL=/cgi-bin/buggy.pl<br />
e07d9cb85217949d497b02d7211de8a197d2f2ebzf </code>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf </blockquote>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <p>note the <code>REDIRECT_</code> prefix.</p>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <p>At least <code>REDIRECT_URL</code> and
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <code>REDIRECT_QUERY_STRING</code> will be passed to the
e07d9cb85217949d497b02d7211de8a197d2f2ebzf new URL (assuming it's a cgi-script or a cgi-include). The
e07d9cb85217949d497b02d7211de8a197d2f2ebzf other variables will exist only if they existed prior to
e07d9cb85217949d497b02d7211de8a197d2f2ebzf the error/problem. <strong>None</strong> of these will be
e07d9cb85217949d497b02d7211de8a197d2f2ebzf set if your ErrorDocument is an <em>external</em> redirect
e07d9cb85217949d497b02d7211de8a197d2f2ebzf (<em>i.e.</em>, anything starting with a scheme name like
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <code>http:</code>, even if it refers to the same host as
e07d9cb85217949d497b02d7211de8a197d2f2ebzf the server).</p>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf </dd>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <dt>Configuration</dt>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <dd>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf Use of "ErrorDocument" is enabled for .htaccess files when
e07d9cb85217949d497b02d7211de8a197d2f2ebzf the <a href="mod/core.html#allowoverride">"FileInfo"
e07d9cb85217949d497b02d7211de8a197d2f2ebzf override</a> is allowed.
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <p>Here are some examples...</p>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <blockquote>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <code>ErrorDocument 500 /cgi-bin/crash-recover<br />
e07d9cb85217949d497b02d7211de8a197d2f2ebzf ErrorDocument 500 "Sorry, our script crashed. Oh
e07d9cb85217949d497b02d7211de8a197d2f2ebzf dear<br />
e07d9cb85217949d497b02d7211de8a197d2f2ebzf ErrorDocument 500 http://xxx/<br />
e07d9cb85217949d497b02d7211de8a197d2f2ebzf ErrorDocument 404 /Lame_excuses/not_found.html<br />
e07d9cb85217949d497b02d7211de8a197d2f2ebzf ErrorDocument 401
e07d9cb85217949d497b02d7211de8a197d2f2ebzf /Subscription/how_to_subscribe.html</code>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf </blockquote>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <p>The syntax is,</p>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <p><code><a
e07d9cb85217949d497b02d7211de8a197d2f2ebzf href="mod/core.html#errordocument">ErrorDocument</a></code>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf &lt;3-digit-code&gt; action</p>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <p>where the action can be,</p>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <ol>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <li>Text to be displayed. Prefix the text with a quote
e07d9cb85217949d497b02d7211de8a197d2f2ebzf ("). Whatever follows the quote is displayed. <em>Note:
e07d9cb85217949d497b02d7211de8a197d2f2ebzf the (") prefix isn't displayed.</em></li>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <li>An external URL to redirect to.</li>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <li>A local URL to redirect to.</li>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf </ol>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf </dd>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf </dl>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <hr />
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <h2>Custom error responses and redirects</h2>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <dl>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <dt>Purpose</dt>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <dd>Apache's behavior to redirected URLs has been modified so
e07d9cb85217949d497b02d7211de8a197d2f2ebzf that additional environment variables are available to a
e07d9cb85217949d497b02d7211de8a197d2f2ebzf script/server-include.</dd>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <dt>Old behavior</dt>
020c47705d28102a8df83a43ddf08e34dde21f22ql
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <dd>Standard CGI vars were made available to a script which
e07d9cb85217949d497b02d7211de8a197d2f2ebzf has been redirected to. No indication of where the
e07d9cb85217949d497b02d7211de8a197d2f2ebzf redirection came from was provided.</dd>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <dt>New behavior</dt>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <dd>A new batch of environment variables will be initialized
e07d9cb85217949d497b02d7211de8a197d2f2ebzf for use by a script which has been redirected to. Each new
e07d9cb85217949d497b02d7211de8a197d2f2ebzf variable will have the prefix <code>REDIRECT_</code>.
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <code>REDIRECT_</code> environment variables are created from
e07d9cb85217949d497b02d7211de8a197d2f2ebzf the CGI environment variables which existed prior to the
e07d9cb85217949d497b02d7211de8a197d2f2ebzf redirect, they are renamed with a <code>REDIRECT_</code>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf prefix, <em>i.e.</em>, <code>HTTP_USER_AGENT</code> becomes
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <code>REDIRECT_HTTP_USER_AGENT</code>. In addition to these
e07d9cb85217949d497b02d7211de8a197d2f2ebzf new variables, Apache will define <code>REDIRECT_URL</code>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf and <code>REDIRECT_STATUS</code> to help the script trace its
e07d9cb85217949d497b02d7211de8a197d2f2ebzf origin. Both the original URL and the URL being redirected to
e07d9cb85217949d497b02d7211de8a197d2f2ebzf can be logged in the access log.</dd>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf </dl>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <p>If the ErrorDocument specifies a local redirect to a CGI
e07d9cb85217949d497b02d7211de8a197d2f2ebzf script, the script should include a "<samp>Status:</samp>"
e07d9cb85217949d497b02d7211de8a197d2f2ebzf header field in its output in order to ensure the propagation
e07d9cb85217949d497b02d7211de8a197d2f2ebzf all the way back to the client of the error condition that
e07d9cb85217949d497b02d7211de8a197d2f2ebzf caused it to be invoked. For instance, a Perl ErrorDocument
e07d9cb85217949d497b02d7211de8a197d2f2ebzf script might include the following:</p>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf<pre>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf :
e07d9cb85217949d497b02d7211de8a197d2f2ebzf print "Content-type: text/html\n";
e07d9cb85217949d497b02d7211de8a197d2f2ebzf printf "Status: %s Condition Intercepted\n", $ENV{"REDIRECT_STATUS"};
e07d9cb85217949d497b02d7211de8a197d2f2ebzf :
e07d9cb85217949d497b02d7211de8a197d2f2ebzf</pre>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <p>If the script is dedicated to handling a particular error
e07d9cb85217949d497b02d7211de8a197d2f2ebzf condition, such as <samp>404&nbsp;Not&nbsp;Found</samp>, it can
e07d9cb85217949d497b02d7211de8a197d2f2ebzf use the specific code and error text instead.</p>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf <!--#include virtual="footer.html" -->
e07d9cb85217949d497b02d7211de8a197d2f2ebzf </body>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf</html>
e07d9cb85217949d497b02d7211de8a197d2f2ebzf
e07d9cb85217949d497b02d7211de8a197d2f2ebzf