Custom Error Messages
Written
Author
The htaccess gives you the ability to redirect the visitor to different pages if they try to access an invalid page. You can use a custom error page for any type of error as long as you know its number. Example: 404 Page Not Found. The layout for this command is:
ErrorDocument errornumber /filename.html
So if you create a page called "NotFound.html" and you wanted to use it as the 404 error page, the command would be:
ErrorDocument 404 /NotFound.html
If you want to keep all of the error pages in a separate directory, just include the directory name in the file path:
ErrorDocument 404 /errorpages/NotFound.html
The most used error documents are:
- 400 - Bad Request: A generic kind of error that people get into by doing some strange stuff with your URL or scripts.
- 401 - Authorization Required: When someone tries to enter a protected area without proper authorization.
- 403 - Forbidden: When a file with permissions not allowing it to be accessed by the user is requested. 404 Not Found Kinda obvious.
- 500- Internal Server Error: This may help you with internal server errors in any scripts you have running.
There are many others, but these are probably all you will ever need to know.