Custom Error Messages In Apache
Contents |
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 custom 500 page users. You may wish to provide custom error responses which are either friendlier, or apache custom error log virtualhost in some language other than English, or perhaps which are styled more in line with your site layout. Customized error apache custom 404 error page 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
Custom Error Messages Rails
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. Configuration Available Variables Customizing Error Responses Multi Language Custom Error Documents See alsoComments Configuration Custom error documents are configured using the ErrorDocument directive, which may be used in php error messages global, virtualhost, or directory context. It may be used in .htaccess files if AllowOverride is set to FileInfo. 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 directive is: ErrorDocument <3-digit-code>
generic error responses in the event of 4xx or 5xx HTTP status mysql error messages codes, these responses are rather stark, uninformative, and can be intimidating
Tomcat Error Messages
to site users. You may wish to provide custom error responses which are either friendlier, or in
Apache Set 404 Page
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 https://httpd.apache.org/docs/2.4/custom-error.html 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 https://httpd.apache.org/docs/trunk/custom-error.html handler (PHP, mod_perl, etc) which makes use of these variables. Configuration Available Variables Customizing Error Responses Multi Language Custom Error Documents See alsoComments Configuration Custom error documents are configured using the ErrorDocument directive, which may be used in global, virtualhost, or directory context. It may be used in .htaccess files if AllowOverride is set to FileInfo. 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 directive is: ErrorDocument <3-digit-code>
you upgrade your browser to one which is compatible with CSS. For more information, please visit our Browser Upgrade page. Home FAQs Forums Links News Online Tools phpBB Scripts Tutorials: Apache CSS Databases Graphics Hosting HTML & XHTML Miscellaneous Perl PHP About us Contact us Contribute http://www.4webhelp.net/tutorials/misc/errors.php Credits Link to us News: RIP Netscape Navigator IP Atlas Updated Tutorial comment spam Forum problems phpBB http://www.debianhelp.co.uk/customerrors.htm Upgrades Search: Creating Custom Error Messages in Apache by eKstreme Last updated: 02/05/2012 Write a tutorial for us Bookmark this tutorial Print this tutorial Comment on this tutorial In order to have a complete understanding of what a .htaccess file is, I suggest that you also read our Control File Defaults tutorial and our Password Protection tutorial. Introduction The .htaccess file is a file found in Apache servers error messages that allows you to manipulate the behaviour of the server. A very common use is to create custom error messages for server errors. Examples of such errors are "404 Not Found" (say when you click on a broken link), and the "500 Internal Server Error" (a script failed). Most hosts allow you to have your own .htaccess file, and so now we will look at only one of the things we can do with a custom .htaccess. Some quick notes before we start: under Windows, you custom error messages cannot save a file with the name of ".htaccess". An easy trick is to create a file called htaccess.txt and edit that. Uploading of the file (regardless of its name) must be done in TEXT/ASCII mode (not BINARY). Finally, under Unix, any file that starts with a '.' is invisible, so when you upload your file, you may not see it. If you uploaded a file called htaccess.txt, just rename it to .htaccess using your FTP client. Custom Error Messages What you can do with .htaccess is tell the server to display a special page to the user in case of an error. This page should, ideally, tell the user that something is wrong, down-play the fact that someone messed up (probably you as the webmaster!), and also provide a set of links to the major sections of the site, so the user can at least look for what is missing. Another nice use is to include a search form on the 404 page. You can also tell the server to run a CGI script, instead of simply displaying a static page. If you do this, you can tell the script to log the error for you, or the script can send you an email about the error. So how do we implement this? Since the .htaccess file is a simple text file, you simply add a line of text to the file, one for each error you want to trap. The general format is: ErrorDocument 3DigitErrorCode /path/to/your/error/file/or/script The 3-Digits error codes are as
custom error messages on the Apache web server This document describes how to configure the Apache web server so that it will redirect common server errors - like 404 Not Found or 500 Internal Server Error - to a Perl CGI script for processing. In order to configure Apache error handling, you must: 1. Edit a ".htaccess" file in the root folder of your web site2. Have the "AllowOverride" privilege granted by the system administrator who set up Apache. (This is automatically the case for the majority of Apache users.)If you do not have the AllowOverride privilege, then you will have to ask your administrator to take these steps on your behalf. Follow these steps to add a custom error page to Apache:1. Before you tweak Apache, first make an initial request to your custom error page using its direct URL. Make sure it displays properly. If your error page is a Perl CGI script, and it is failing, then it will be very difficult to debug what is going on when other errors are redirected to it. 2. Some FTP servers and FTP client software do not allow the viewing or manipulation of files that begin with a dot, like ".htaccess". Some systems will allow you to upload files named ".htaccess", but once the file is on the server, the file won't appear in your file list and you won't be able to delete or rename it - which will be a problem if the .htaccess file makes your site inaccessible.So, first, create an empty file named ".test". Upload it to your site. Will your FTP client software allow it? Will the FTP server accept it? Can you then rename and delete the file? If you have trouble with any of these operations, then you should not proceed to .htaccess. Instead contact your system administrator to see about getting the right software/settings for the job.3. Before beginning, request a file from your website that doesn't exist, like www.test.com/no_such_file. Observe the 404 Not Found error handling: do you see a plaintext file like "404 Not Found"? Or do you see a pretty error message that someone else has already customized, perhaps one specific to your web hosting company? Or are you redirected to a special file, like www.test.com/404.html? You need to know what the baseline behavior is so that you can evaluate the behavior later a