From: Rich Bowen
Additional functionality allows webmasters to configure the response - of Apache to some error or problem.
-Customizable responses can be defined to be activated in the event of - a server detected error or problem.
+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 indimidating 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.
-If a script crashes and produces a "500 Server Error" response, - then this response can be replaced with either some friendlier text or by - a redirection to another URL (local or external).
-Custom error documents are configured using the ErrorDocument
directive.
+ ErrorDocument
, which may be used in global,
+ virtualhost, or directory context. It may be used in .htaccess files
+ if AllowOverride
is set to
+ FileInfo.
NCSA httpd 1.3 would return some boring old error/problem message - which would often be meaningless to the user, and would provide no - means of logging the symptoms which caused it.
- +
+ 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 ErrorDocuemnt
directrive is:
The server can be asked to:
+
+ ErrorDocument <3-digit-code> <action>
+
where the action can be one of:
-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.
+ +Redirecting to another URL can be useful, but only if some - information can be passed which can then be used to explain and/or log - the error/problem more clearly.
+ information can be passed which can then be used to explain or log + the error condition more clearly. -To achieve this, Apache will define new CGI-like environment - variables:
+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 recieve, in addition to more usual + environment variables, the following.
- REDIRECT_HTTP_ACCEPT=*/*, image/gif, image/x-xbitmap,
- image/jpeg
- REDIRECT_HTTP_USER_AGENT=Mozilla/1.1b2 (X11; I; HP-UX A.09.05
- 9000/712)
- REDIRECT_PATH=.:/bin:/usr/local/bin:/etc
+ REDIRECT_HTTP_ACCEPT=*/*, image/gif, image/jpeg, image/png
+ REDIRECT_HTTP_USER_AGENT=Mozilla/5.0 Fedora/3.5.8-1.fc12 Firefox/3.5.8
+ REDIRECT_PATH=.:/bin:/usr/local/bin:/sbin
REDIRECT_QUERY_STRING=
REDIRECT_REMOTE_ADDR=121.345.78.123
- REDIRECT_REMOTE_HOST=ooh.ahhh.com
- REDIRECT_SERVER_NAME=crash.bang.edu
+ REDIRECT_REMOTE_HOST=client.example.com
+ REDIRECT_SERVER_NAME=www.example.edu
REDIRECT_SERVER_PORT=80
- REDIRECT_SERVER_SOFTWARE=Apache/0.8.15
+ REDIRECT_SERVER_SOFTWARE=Apache/2.2.15
REDIRECT_URL=/cgi-bin/buggy.pl
Note the REDIRECT_
prefix.
REDIRECT_
environment variables are created from
+ the environment variables which existed prior to the
+ redirect. They are renamed with a REDIRECT_
+ prefix, i.e., HTTP_USER_AGENT
becomes
+ REDIRECT_HTTP_USER_AGENT
.
At least REDIRECT_URL
and
- REDIRECT_QUERY_STRING
will be passed to the
- new URL (assuming it's a cgi-script or a cgi-include). The
- other variables will exist only if they existed prior to
- the error/problem. None of these will be
- set if your ErrorDocument
is an
+
REDIRECT_URL
, REDIRECT_STATUS
, and
+ REDIRECT_QUERY_STRING
are guaranteed to be set, and
+ the other headers will be set only if they existed prior to the
+ error condition.
None of these will be
+ set if the ErrorDocument
target is an
external redirect (anything starting with a
scheme name like http:
, even if it refers to the same host
as the server).
Use of ErrorDocument
is enabled
- for .htaccess files when the
- AllowOverride
is set to FileInfo.
Here are some examples...
- -
- ErrorDocument 500 /cgi-bin/crash-recover
- ErrorDocument 500 "Sorry, our script crashed. Oh dear"
- ErrorDocument 500 http://xxx/
- ErrorDocument 404 /Lame_excuses/not_found.html
- ErrorDocument 401 /Subscription/how_to_subscribe.html
-
The syntax is,
- -
- ErrorDocument <3-digit-code> <action>
-
where the action can be,
- -Apache's behavior to redirected URLs has been modified so - that additional environment variables are available to a - script/server-include.
- -Standard CGI vars were made available to a script which - has been redirected to. No indication of where the - redirection came from was provided.
- - -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 REDIRECT_
.
- REDIRECT_
environment variables are created from
- the CGI environment variables which existed prior to the
- redirect, they are renamed with a REDIRECT_
- prefix, i.e., HTTP_USER_AGENT
becomes
- REDIRECT_HTTP_USER_AGENT
. In addition to these
- new variables, Apache will define REDIRECT_URL
- and REDIRECT_STATUS
to help the script trace its
- origin. Both the original URL and the URL being redirected to
- can be logged in the access log.
If you point your ErrorDocument
to some variety of
+ dynamic handler such as a server-side include document, CGI
+ script, or some variety of other handler, you may wish to use the
+ available custom environent variables to customize this
+ response.
If the ErrorDocument specifies a local redirect to a CGI
script, the script should include a "Status:
"
@@ -186,13 +161,46 @@
condition, such as 404 Not Found
, it can
use the specific code and error text instead.
Note that the script must emit an appropriate
- Status:
header (such as 302 Found
), if the
- response contains a Location:
header (in order to issue a
- client side redirect). Otherwise the Location:
header may
- have no effect.
Note that if the response contains Location:
+ header (in order to issue a client-side redirect), the script
+ must emit an appropriate Status:
header
+ (such as 302 Found
). Otherwise the
+ Location:
header may have no effect.
Provided 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
+ conf/extra
configuration directory that can be included
+ to enable this feature.
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 Include
line will enable this
+ feature, and provide language-negotiated error messages, based on
+ the language preference set in the client browser.
Additionally, these documents contain various of the
+ REDIRECT_
variables, so that additional information can
+ be provided to the end-user about what happened, and what they can
+ do now.
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.
+ +mod_includes
and mod_negotiation
+ must be enabled to use this feature.
Available Languages: en | es | diff --git a/docs/manual/custom-error.xml b/docs/manual/custom-error.xml index 3475337087..19ed890eee 100644 --- a/docs/manual/custom-error.xml +++ b/docs/manual/custom-error.xml @@ -25,142 +25,117 @@
Additional functionality allows webmasters to configure the response - of Apache to some error or problem.
-Customizable responses can be defined to be activated in the event of - a server detected error or problem.
+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 indimidating 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.
-If a script crashes and produces a "500 Server Error" response, - then this response can be replaced with either some friendlier text or by - a redirection to another URL (local or external).
Custom error documents are configured using the ErrorDocument
, which may be used in global,
+ virtualhost, or directory context. It may be used in .htaccess files
+ if
NCSA httpd 1.3 would return some boring old error/problem message - which would often be meaningless to the user, and would provide no - means of logging the symptoms which caused it.
-The syntax of the ErrorDocuemnt
directrive is:
The server can be asked to:
+where the action can be one of:
-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.
+ +Redirecting to another URL can be useful, but only if some - information can be passed which can then be used to explain and/or log - the error/problem more clearly.
+ information can be passed which can then be used to explain or log + the error condition more clearly. -To achieve this, Apache will define new CGI-like environment - variables:
+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 recieve, in addition to more usual + environment variables, the following.
Note the REDIRECT_
prefix.
REDIRECT_
environment variables are created from
+ the environment variables which existed prior to the
+ redirect. They are renamed with a REDIRECT_
+ prefix, i.e., HTTP_USER_AGENT
becomes
+ REDIRECT_HTTP_USER_AGENT
.
REDIRECT_URL
, REDIRECT_STATUS
, and
+ REDIRECT_QUERY_STRING
are guaranteed to be set, and
+ the other headers will be set only if they existed prior to the
+ error condition.
At least REDIRECT_URL
and
- REDIRECT_QUERY_STRING
will be passed to the
- new URL (assuming it's a cgi-script or a cgi-include). The
- other variables will exist only if they existed prior to
- the error/problem. None of these will be
- set if your
None of these will be
+ set if the http:
, even if it refers to the same host
as the server).
Use of
Here are some examples...
- -The syntax is,
+where the action can be,
- -Apache's behavior to redirected URLs has been modified so - that additional environment variables are available to a - script/server-include.
- -Standard CGI vars were made available to a script which - has been redirected to. No indication of where the - redirection came from was provided.
-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 REDIRECT_
.
- REDIRECT_
environment variables are created from
- the CGI environment variables which existed prior to the
- redirect, they are renamed with a REDIRECT_
- prefix, i.e., HTTP_USER_AGENT
becomes
- REDIRECT_HTTP_USER_AGENT
. In addition to these
- new variables, Apache will define REDIRECT_URL
- and REDIRECT_STATUS
to help the script trace its
- origin. Both the original URL and the URL being redirected to
- can be logged in the access log.
If you point your ErrorDocument
to some variety of
+ dynamic handler such as a server-side include document, CGI
+ script, or some variety of other handler, you may wish to use the
+ available custom environent variables to customize this
+ response.
If the ErrorDocument specifies a local redirect to a CGI
script, the script should include a "Status:
"
@@ -180,11 +155,45 @@
condition, such as 404 Not Found
, it can
use the specific code and error text instead.
Note that the script must emit an appropriate
- Status:
header (such as 302 Found
), if the
- response contains a Location:
header (in order to issue a
- client side redirect). Otherwise the Location:
header may
- have no effect.
Note that if the response contains Location:
+ header (in order to issue a client-side redirect), the script
+ must emit an appropriate Status:
header
+ (such as 302 Found
). Otherwise the
+ Location:
header may have no effect.
Provided 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
+ conf/extra
configuration directory that can be included
+ to enable this feature.
In your server configuration file, you'll see a line such as:
+ +Uncommenting this Include
line will enable this
+ feature, and provide language-negotiated error messages, based on
+ the language preference set in the client browser.
Additionally, these documents contain various of the
+ REDIRECT_
variables, so that additional information can
+ be provided to the end-user about what happened, and what they can
+ do now.
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.
+ +