Раздел 2. Using the Apache HTTP Server RU EN Пункт 17. Custom error responses Although the Apache HTTP Server provides generic error responses in the event of 4xx or 5xx HTTP status codes, these responses are rather stark, uninformative, and can be intimidating to site users. You may wish to provide custom error responses which are either friendlier, or in some language other than English, or perhaps which are styled more in line with your site layout. Customized error responses can be defined for any HTTP status code designated as an error condition - that is, any 4xx or 5xx status. Additionally, a set of values are provided, so that the error document can be customized further based on the values of these variables, using Server Side Includes. Or, you can have error conditions handled by a cgi program, or other dynamic handler (PHP, mod_perl, etc) which makes use of these variables. ConfigurationCustom error documents are configured using the ErrorDocument 500 "Sorry, our script crashed. Oh dear" ErrorDocument 500 /cgi-bin/crash-recover ErrorDocument 500 http://error.example.com/server_error.html ErrorDocument 404 /errors/not_found.html ErrorDocument 401 /subscription/how_to_subscribe.html The syntax of the ErrorDocument <3-digit-code> <action> where the action will be treated as:
When redirecting to a local URL, additional environment variables are set so that the response can be further customized. They are not sent to external URLs. Available VariablesRedirecting to another URL can be useful, but only if some information can be passed which can then be used to explain or log the error condition more clearly. To achieve this, when the error redirect is sent, additional environment variables will be set, which will be generated from the headers provided to the original request by prepending 'REDIRECT_' onto the original header name. This provides the error document the context of the original request. For example, you might receive, in addition to more usual environment variables, the following. None of these will be
set if the Customizing Error ResponsesIf you point your If the ErrorDocument specifies a local redirect to a CGI
script, the script should include a " ... print "Content-type: text/html\n"; printf "Status: %s Condition Intercepted\n", $ENV{"REDIRECT_STATUS"}; ... If the script is dedicated to handling a particular error
condition, such as Note that if the response contains Multi Language Custom Error DocumentsProvided with your installation of the Apache HTTP Server is a
directory of custom error documents translated into 16 different
languages. There's also a configuration file in the
In your server configuration file, you'll see a line such as: # Multi-language error messages #Include conf/extra/httpd-multilang-errordoc.conf Uncommenting this Additionally, these documents contain various of the
These documents can be customized to whatever degree you wish to provide more useful information to users about your site, and what they can expect to find there. |
![]() |