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