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