Error Documents with htaccess – A Comprehensive guide to htaccess

Spread the love

Error Documents with htaccess – A Comprehensive guide to htaccess. You’re likely going to want to create an error file for 404 and 500 codes, at least 404, as this would offer you an advantage to manage applications for unfindable websites. 500 Any scripts you have running would assist you with internal server errors.

Default 403 error page

 

Apache 500 error page

Default 500 error page

You may also want to consider ErrorDocuments for 401 — Authorization Required (such as when someone tries to enter a protected area of your site without proper credentials), 403 — Forbidden (such as when a file with permissions that don’t allow the user to access it is requested) and 400 — Bad Request, which is one of those generic types of mistakes that individuals make by doing strange things with URL or script

In order to specify your own customized error documents, you simply need to add the following command, on one line, within your htaccess file:

ErrorDocument code /directory/filename.ext
or
ErrorDocument 404 /errors/notfound.html

Likewise with:
ErrorDocument 500 /errors/internalerror.html

If you were to use an error document handler for each of the error codes I mentioned, the htaccess file would look like the following (note each command is on its own line):

ErrorDocument 400 /errors/badrequest.html
ErrorDocument 401 /errors/authreqd.html
ErrorDocument 403 /errors/forbid.html
ErrorDocument 404 /errors/notfound.html
ErrorDocument 500 /errors/serverr.html

You can also specify in HTML or text,

ErrorDocument 401 "You have to actually BE a member to view this page!"

I will mention some error code and its meaning. It will be useful for you.

Successful Client Requests

200 OK
201 Created
202 Accepted
203 Non-Authoritative Information
204 No Content
205 Reset Content
206 Partial Content

Client Request Redirected

300 Multiple Choices
301 Moved Permanently
302 Moved Temporarily
303 See Other
304 Not Modified
305 Use Proxy

Client Request Errors

400 Bad Request
401 Authorization Required
402 Payment Required (not used yet)
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable (encoding)
407 Proxy Authentication Required
408 Request Timed Out
409 Conflicting Request
410 Gone
411 Content-Length Required
412 Precondition Failed
413 Request Entity Too Long
414 Request URI Too Long
415 Unsupported Media Type

Server Errors

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

 


Spread the love

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *