Handle 404, 500, and 301 Errors as Well as Many Others With an .htaccess file
Code & Scripts, Programming, Quick Tips
Lets suppose you wanted to redirect users to your home page if they attempted to access a page that was NOT on your server. There is a very quick and simple way to do this. Its called a 404 redirect using an .htaccess file. You simply create a new file in Microsoft Notepad and type this: “ErrorDocument 404 /index.php” (Without the quotes). Then you simply save the file as .htaccess and upload it to your root directory. From now on when someone visits www.yoursite.com/chickentastes/good.html they will automatically be redirected to your homepage.
Interestingly enough you can also redirect to a specific page such as a custom 400 error page that you code up in php or html or whatever. See examples below. Just replace the “/errors/badrequest.html” part with “/myCustom400ErrorPage.php” and you’ll be fine.
Please find below a pretty copmplete list of server returned errors.
Successful Client Requests- 200 OK
- 201 Created
- 202 Accepted
- 203 Non-Authorative Information
- 204 No Content
- 205 Reset Content
- 206 Partial Content
- 300 Multiple Choices
- 301 Moved Permanently
- 302 Moved Temporarily
- 303 See Other
- 304 Not Modified
- 305 Use Proxy
- 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
- 500 Internal Server Error
- 501 Not Implemented
- 502 Bad Gateway
- 503 Service Unavailable
- 504 Gateway Timeout
- 505 HTTP Version Not Supported
If you enjoyed this article please consider leaving a comment or subscribing to the feed and get future articles delivered to your feed reader.
Previous Post: 11 Inspirational and Well Designed Logos to Inspire Your Next Project
Next Post: 5 of The Most Beneficial and Essential WordPress Plugins Ever Coded
You May Also Enjoy One Of These Posts:
- DamnIT is a Free Service That Emails You When a User Encounters a JavaScript Error on One of Your Webpages
- Completely Free Ways to Check if Your Website’s HTML Web Pages are Compliant & Valid With W3 Standards
- PSPad is an AWESOME FreeWare Windows Based Text Editor/IDE for Many Programming Languages
- 5 of The Most Beneficial and Essential WordPress Plugins Ever Coded
- 5 More of The Most Beneficial and Essential WordPress Plugins Ever Coded
Tags: Code & Scripts, Programming, Quick Tips





Twitter
Facebook
RSS
Technorati
StumbleUpon
Most of the people i know prefers to get a specialist’s help when it comes to this kind of errors. I think this is the best thing to do when you really don’t know how these things work, or at least you should get some assistance for all this kind of changes you want to have on your website.