📄 custom_errordocs.html.en
字号:
and in mod_include.</p> <p>See <a href="#listings">the listings below</a> to see an actual HTML implementation of the discussed example.</p> <h3><a name="createdocs" id="createdocs">Creating ErrorDocuments in Different Languages</a></h3> <p>After all this preparation work, little remains to be said about the actual documents. They all share a simple common structure:</p><div class="example"><p><code><!--#set var="title" value="<em>error description title</em>" --> <br /><!--#include virtual="head" --> <br /><span class="indent"> <em>explanatory error text</em> <br /></span><!--#include virtual="foot" --></code></p></div> <p>In the <a href="#listings">listings section</a>, you can see an example of a [400 Bad Request] error document. Documents as simple as that certainly cause no problems to translate or expand.</p> <h3><a name="fallback" id="fallback">The Fallback Language</a></h3> <p>Do we need a special handling for languages other than those we have translations for? We did set the LanguagePriority, didn't we?!</p> <p>Well, the LanguagePriority directive is for the case where the client does not express any language priority at all. But what happens in the situation where the client wants one of the languages we do not have, and none of those we do have?</p> <p>Without doing anything, the Apache server will usually return a [406 no acceptable variant] error, listing the choices from which the client may select. But we're in an error message already, and important error information might get lost when the client had to choose a language representation first.</p> <p>So, in this situation it appears to be easier to define a fallback language (by copying or linking, <em>e.g.</em>, the english version to a language-less version). Because the negotiation algorithm prefers "more specialized" variants over "more generic" variants, these generic alternatives will only be chosen when the normal negotiation did not succeed.</p> <p>A simple shell script to do it (execute within the errordocs/ dir):</p><div class="example"><p><code> for f in *.shtml.en <br /> do <br /> <span class="indent"> ln -s $f `basename $f .en` <br /> </span> done</code></p></div> </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2><a name="proxy" id="proxy">Customizing Proxy Error Messages</a></h2> <p>As of Apache-1.3, it is possible to use the <code>ErrorDocument</code> mechanism for proxy error messages as well (previous versions always returned fixed predefined error messages).</p> <p>Most proxy errors return an error code of [500 Internal Server Error]. To find out whether a particular error document was invoked on behalf of a proxy error or because of some other server error, and what the reason for the failure was, you can check the contents of the new <code>ERROR_NOTES</code> CGI environment variable: if invoked for a proxy error, this variable will contain the actual proxy error message text in HTML form.</p> <p>The following excerpt demonstrates how to exploit the <code>ERROR_NOTES</code> variable within an error document:</p><div class="example"><p><code> <!--#if expr="$REDIRECT_ERROR_NOTES = ''" --> <br /> <br /> <p> <br /> <span class="indent"> The server encountered an unexpected condition <br /> which prevented it from fulfilling the request. <br /> </span> </p> <br /><br /> <p> <br /> <span class="indent"> <a href="mailto:<!--#echo var="SERVER_ADMIN" -->" <br /> SUBJECT="Error message [<!--#echo var="REDIRECT_STATUS" -->] <!--#echo var="title" --> for <!--#echo var="REQUEST_URI" -->"> <br /> Please forward this error screen to <!--#echo var="SERVER_NAME" -->'s <br /> WebMaster</a>; it includes useful debugging information about <br /> the Request which caused the error. <br /><br /> <pre><!--#printenv --></pre> <br /> </span> </p> <br /> <br /> <!--#else --> <br /> <span class="indent"> <!--#echo var="REDIRECT_ERROR_NOTES" --><br /> </span><br /> <!--#endif --></code></p></div> </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2><a name="listings" id="listings">HTML Listing of the Discussed Example</a></h2> <p>So, to summarize our example, here's the complete listing of the <code>400.shtml.en</code> document. You will notice that it contains almost nothing but the error text (with conditional additions). Starting with this example, you will find it easy to add more error documents, or to translate the error documents to different languages.</p><div class="example"><p><code><!--#set var="title" value="Bad Request"--> <br /><!--#include virtual="head" --><br /><br /> <p> <br /> <span class="indent"> Your browser sent a request that this server could not understand: <br /> <blockquote> <br /> <span class="indent"> <strong><!--#echo var="REQUEST_URI" --></strong><br /> </span> </blockquote> <br /> <br /> The request could not be understood by the server due to malformed <br /> syntax. The client should not repeat the request without <br /> modifications. <br /> </span> </p> <br /><br /> <p> <br /> <span class="indent"> <!--#if expr="$HTTP_REFERER != ''" --> <br /> <span class="indent"> Please inform the owner of <br /> <a href="<!--#echo var="HTTP_REFERER" -->">the referring page</a> about <br /> the malformed link. <br /> </span> <br /> <!--#else --> <br /> <span class="indent"> Please check your request for typing errors and retry. <br /> </span> <br /> <!--#endif --> <br /> </span> </p> <br /><br /><!--#include virtual="foot" --></code></p></div> <p>Here is the complete <code>head.shtml.en</code> file (the funny line breaks avoid empty lines in the document after SSI processing). Note the configuration section at top. That's where you configure the images and logos as well as the apache documentation directory. Look how this file displays two different logos depending on the content of the virtual host name ($SERVER_NAME), and that an animated apache logo is shown if the browser appears to support it (the latter requires server configuration lines of the form </p> <div class="example"><p><code>BrowserMatch "^Mozilla/[2-4]" anigif</code></p></div> <p>for browser types which support animated GIFs).</p><div class="example"><p><code><!--#if expr="$SERVER_NAME = /.*\.mycompany\.com/" --><br /><span class="indent"><!--#set var="IMG_CorpLogo" value="http://$SERVER_NAME:$SERVER_PORT/errordocs/CorpLogo.gif" --><br /><!--#set var="ALT_CorpLogo" value="Powered by Linux!" --><br /></span><br /><!--#else --> <br /><span class="indent"><!--#set var="IMG_CorpLogo" value="http://$SERVER_NAME:$SERVER_PORT/errordocs/PrivLogo.gif" --> <br /><!--#set var="ALT_CorpLogo" value="Powered by Linux!" --> <br /></span><!--#endif--> <br /><br /><!--#set var="IMG_BgImage" value="http://$SERVER_NAME:$SERVER_PORT/errordocs/BgImage.gif" --> <br /><!--#set var="DOC_Apache" value="http://$SERVER_NAME:$SERVER_PORT/Apache/" --> <br /><br /><!--#if expr="$anigif" --> <br /><span class="indent"><!--#set var="IMG_Apache" value="http://$SERVER_NAME:$SERVER_PORT/icons/apache_anim.gif" --> <br /></span><!--#else--><br /><span class="indent"><!--#set var="IMG_Apache" value="http://$SERVER_NAME:$SERVER_PORT/icons/apache_pb.gif" --><br /></span><!--#endif--><br /><br /><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <br /><html> <br /><head> <br /> <span class="indent"> <title> <br /> [<!--#echo var="REDIRECT_STATUS" -->] <!--#echo var="title" --> <br /> </title> <br /> </span></head> <br /><br /><body bgcolor="white" background="<!--#echo var="IMG_BgImage" -->"> <br /><span class="indent"> <h1 align="center"> <br /> [<!--#echo var="REDIRECT_STATUS" -->] <!--#echo var="title" --> <br /> <img src="<!--#echo var="IMG_CorpLogo" -->" <br /> alt="<!--#echo var="ALT_CorpLogo" -->" align="right"> <br /> </h1> <br /><br /> <hr /> <!-- ======================================================== --> <br /> <div></span></code></p></div> <p>and this is the <code>foot.shtml.en</code> file:</p><div class="example"><p><code><span class="indent"> </div> <br /> <hr /> <br /> <br /> <div align="right"> <br /> <span class="indent"> <small>Local Server time: <!--#echo var="DATE_LOCAL" --></small> <br /> </span> </div> <br /> <br /> <div align="center"><br /> <span class="indent"> <a href="<!--#echo var="DOC_Apache" -->"> <br /> <img src="<!--#echo var="IMG_Apache" -->" border="0" align="bottom" <br /> alt="Powered by <!--#echo var="SERVER_SOFTWARE" -->"></a> <br /> <br /><br /> <small><!--#set var="var" value="Powered by $SERVER_SOFTWARE -- <br /> File last modified on $LAST_MODIFIED" --> <br /> <!--#echo var="var" --></small> <br /> </span> </div> <br /> <br /> <p>If the indicated error looks like a misconfiguration, please inform <br /> <a href="mailto:<!--#echo var="SERVER_ADMIN" -->" <br /> subject="Feedback about Error message [<!--#echo var="REDIRECT_STATUS" -->] <br /> <!--#echo var="title" -->, req=<!--#echo var="REQUEST_URI" -->"> <br /> <!--#echo var="SERVER_NAME" -->'s WebMaster</a>.<br /> </p><br /> </span><br /></body><br /></html></code></p></div> <p>If you have tips to contribute, send mail to <a href="mailto:martin@apache.org">martin@apache.org</a></p> </div></div><div class="bottomlang"><p><span>Available Languages: </span><a href="../en/misc/custom_errordocs.html" title="English"> en </a></p></div><div id="footer"><p class="apache">Copyright 2007 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p><p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -