If you do not have custom files for handling error conditions and error codes like 404 ,500 and 401 etc ,the user experience would not be great. No one prefer to see the “404 Not Found” on their browser.The website developer should handle these scenarios.
You can do this by specifying the custom error document in your server web server configuration files.For Apache server you can do this by editing the .htaccess file.
Here given below are few of the common error codes and we can handle these
Client request Errors
400 – Bad request
401 – Authorization Required
403 – Forbidden
404 – Not Found
Server Errors
500 – Internal Server Error
501 – Not Implemented
502 – Bad Gateway
503 – Service Unavailable
504 – Gateway Timeout
505 – HTTP Version Not Supported
Here is the syntax to specify the error document.
1 2 3 4 | ErrorDocument errornumber /Customfile.html OR ErrorDocument code /directory/Customfile.extension |
if you use the second example above you can keep the custom error file in any directory and use the directory name to replace “directory”.
For example
1 2 3 4 5 6 | ErrorDocument 404 /MissingFile.html OR ErrorDocument 403 /errors/ForbiddenFile.html ErrorDocument 404 /errors/MissingFile.html ErrorDocument 500 /errors/ServerError.html |
Even though it is not advised you can specify a full URL rather than a virtual URL in the ErrorDocument string like http://abcd.com/errors/notfound.html rather than /errors/notfound.html.
Related articles
- 7 steps to Speed up website loading – Website Optimization Tips -Part 1
- Speed up website -Compress CSS/JavaScript using GZIP/DEFLATE compression – Optimization Tips -Part 2
- Check website/ web page for css/script Gzip/ Deflate compression – Optimization Tips -Part 3
Before you go, subscribe to get latest technology articles right in your mailbox!.