Htaccess file performs a very important role to handle errors in on apache web server. When any error ocurrs in your web application like 404(Resource not found) or 500(Internal Server Error) or any other like 403, 401 etc. you can redirect these error pages to your custom pages by using of htaccess ErrorDocument redirect.

Add following lines in .htaccess file to redirect  -

##ErrorDocument Status_Code /path/your_page.html##
ErrorDocument 400 /badrequest.html
ErrorDocument 401 /authreq.html
ErrorDocument 403 /forbid.html
ErrorDocument 404 /pagenotfound.html
ErrorDocument 500 /serverror.html

Note→ If you are going to use these error handling technique you must aware with the meaning of all HTTP status code. If you are going to handle 200 status code then is not good because an ErrorDocument for code 200 would cause an infinite loop.

List of HTTP Status code and their meaning-

1xx Informational Code
100 – Continue
101 – Switching Protocols

2xx Successful Code
200 – OK
201 – Created
202 – Accepted
203 – Non-Authoritative Information
204 – No Content
205 – Reset Content
206 – Partial Content

3xx Redirection Code
300 – Multiple Choices
301 – Moved Permanently
302 – Found
303 – See Other
304 – Not Modified
305 – Use Proxy
307 – Temporary Redirect

4xx Client Error Code
400 – Bad Request
401 – Unauthorized
402 – Payment Required
403 – Forbidden
404 – Not Found
405 – Method Not Allowed
406 – Not Acceptable
407 – Proxy Authentication Required
408 – Request Timeout
409 – Conflict
410 – Gone
411 – Length Required
412 – Precondition Failed
413 – Request Entity Too Large
414 – Request-URI Too Long
415 – Unsupported Media Type
416 – Requested Range Not Satisfiable
417 – Expectation Failed

5xx Server Error Code
500 – Internal Server Error
501 – Not Implemented
502 – Bad Gateway
503 – Service Unavailable
504 – Gateway Timeout
505 – HTTP Version Not Supported

Read details of above codes here.