custom-error.html revision db81e057b060e365d840d9a1d35a5797192efa81
3980N/A<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
3980N/A<HTML>
4586N/A<HEAD>
4586N/A<TITLE>Custom error responses</TITLE>
4586N/A</HEAD>
4586N/A
4305N/A<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
4586N/A<BODY
4586N/A BGCOLOR="#FFFFFF"
4619N/A TEXT="#000000"
4619N/A LINK="#0000FF"
4490N/A VLINK="#000080"
4586N/A ALINK="#FF0000"
4586N/A>
4586N/A<!--#include virtual="header.html" -->
4586N/A<H1 ALIGN="CENTER">Custom error responses</H1>
4586N/A
4586N/A<DL>
4586N/A
4586N/A<DT>Purpose
4586N/A
4586N/A <DD>Additional functionality. Allows webmasters to configure the response of
4586N/A Apache to some error or problem.
4619N/A
3980N/A <P>Customizable responses can be defined to be activated in the
3980N/A event of a server detected error or problem.
4586N/A
4586N/A <P>e.g. if a script crashes and produces a "500 Server Error"
4586N/A response, then this response can be replaced with either some
4586N/A friendlier text or by a redirection to another URL (local or
4586N/A external).
4619N/A <P>
4305N/A
4619N/A<DT>Old behavior
4490N/A
4490N/A <DD>NCSA httpd 1.3 would return some boring old error/problem message
4586N/A which would often be meaningless to the user, and would provide no
4586N/A means of logging the symptoms which caused it.<BR>
4586N/A
4586N/A <P>
4586N/A
4586N/A<DT>New behavior
4586N/A
4586N/A <DD>The server can be asked to;
4586N/A <OL>
4586N/A <LI>Display some other text, instead of the NCSA hard coded messages, or
4586N/A <LI>redirect to a local URL, or
4586N/A <LI>redirect to an external URL.
4490N/A </OL>
4490N/A
4490N/A <P>Redirecting to another URL can be useful, but only if some information
4490N/A can be passed which can then be used to explain and/or log the error/problem
4586N/A more clearly.
4586N/A
4586N/A <P>To achieve this, Apache will define new CGI-like environment
4586N/A variables, e.g.
4586N/A
4586N/A <blockquote><code>
4586N/AREDIRECT_HTTP_ACCEPT=*/*, image/gif, image/x-xbitmap, image/jpeg <br>
4619N/AREDIRECT_HTTP_USER_AGENT=Mozilla/1.1b2 (X11; I; HP-UX A.09.05 9000/712) <br>
4619N/AREDIRECT_PATH=.:/bin:/usr/local/bin:/etc <br>
4619N/AREDIRECT_QUERY_STRING= <br>
4586N/AREDIRECT_REMOTE_ADDR=121.345.78.123 <br>
4586N/AREDIRECT_REMOTE_HOST=ooh.ahhh.com <br>
4586N/AREDIRECT_SERVER_NAME=crash.bang.edu <br>
4586N/AREDIRECT_SERVER_PORT=80 <br>
4586N/AREDIRECT_SERVER_SOFTWARE=Apache/0.8.15 <br>
4586N/AREDIRECT_URL=/cgi-bin/buggy.pl <br>
4490N/A </code></blockquote>
4490N/A
4490N/A <P>note the <code>REDIRECT_</code> prefix.
4619N/A
4586N/A <P>At least <code>REDIRECT_URL</code> and <code>REDIRECT_QUERY_STRING</code> will
4586N/A be passed to the new URL (assuming it's a cgi-script or a cgi-include). The
4619N/A other variables will exist only if they existed prior to the error/problem.
4586N/A <b>None</b> of these will be set if your ErrorDocument is an
4586N/A <i>external</i> redirect (i.e. anything starting with a protocol name
4586N/A like <code>http:</code>, even if it refers to the same host as the
4586N/A server).<p>
4586N/A
4586N/A<DT>Configuration
4586N/A
4586N/A <DD> Use of "ErrorDocument" is enabled for .htaccess files when the
4586N/A <A HREF="mod/core.html#allowoverride">"FileInfo" override</A> is allowed.
4586N/A
4586N/A <P>Here are some examples...
4586N/A
4586N/A <blockquote><code>
4586N/AErrorDocument 500 /cgi-bin/crash-recover <br>
4586N/AErrorDocument 500 "Sorry, our script crashed. Oh dear<br>
4586N/AErrorDocument 500 http://xxx/ <br>
4586N/AErrorDocument 404 /Lame_excuses/not_found.html <br>
4619N/AErrorDocument 401 /Subscription/how_to_subscribe.html
4619N/A </code></blockquote>
3980N/A
4490N/A <P>The syntax is,
4490N/A
4586N/A <P><code><A HREF="mod/core.html#errordocument">ErrorDocument</A></code>
4586N/A&lt;3-digit-code&gt; action
4490N/A
4490N/A <P>where the action can be,
4490N/A
4586N/A <OL>
4586N/A <LI>Text to be displayed. Prefix the text with a quote (&quot;). Whatever
4586N/A follows the quote is displayed. <em>Note: the (&quot;) prefix isn't
4586N/A displayed.</em>
4586N/A
4586N/A <LI>An external URL to redirect to.
4586N/A
4586N/A <LI>A local URL to redirect to.
4490N/A
4490N/A </OL>
4490N/A</DL>
4586N/A
4586N/A<P><HR><P>
4586N/A
4586N/A<h2>Custom error responses and redirects</H2>
3980N/A
3980N/A<DL>
4490N/A
4490N/A<DT>Purpose
4490N/A
4490N/A <DD>Apache's behavior to redirected URLs has been modified so that additional
4490N/A environment variables are available to a script/server-include.<p>
4586N/A
4490N/A<DT>Old behavior
4490N/A
<DD>Standard CGI vars were made available to a script which has been
redirected to. No indication of where the redirection came from was provided.
<p>
<DT>New behavior
<DD>
A new batch of environment variables will be initialized for use by a
script which has been redirected to. Each new variable will have the
prefix <code>REDIRECT_</code>. <code>REDIRECT_</code> environment
variables are created from the CGI environment variables which existed
prior to the redirect, they are renamed with a <code>REDIRECT_</code>
prefix, i.e. <code>HTTP_USER_AGENT</code> becomes
<code>REDIRECT_HTTP_USER_AGENT</code>. In addition to these new
variables, Apache will define <code>REDIRECT_URL</code> and
<code>REDIRECT_STATUS</code> to help the script trace its origin.
Both the original URL and the URL being redirected to can be logged in
the access log.
</DL>
<!--#include virtual="footer.html" -->
</BODY>
</HTML>