P. 1
Comprehensive Guide to Htaccess Error Documents

Comprehensive Guide to Htaccess Error Documents

|Views: 1|Likes:
Published by Mohammed

More info:

Published by: Mohammed on Dec 25, 2011
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





Comprehensive guide to .

htaccess- error documents


Search JavaScript Kit
Categories: All Free JavaScripts/ Applets Tutorials References

Error Documents
This seems to be what people think htaccess was meant for, but it is only part of the general use. We'll be getting into progressively more advanced stuff after this. In order to specify your own ErrorDocuments, you need to be slightly familiar with the server returned error codes. (List to the right). You do not need to specify error pages for all of these, in fact you shouldn't. An ErrorDocument for code 200 would cause an infinite loop, whenever a page was found...this would not be good. You will probably want to create an error document for codes 404 and 500, at the least 404 since this would give you a chance to handle requests for pages not found. 500 would help you out with internal server errors in any scripts you have running. You may also want to consider ErrorDocuments for 401 - Authorization Required (as in when somebody tries to enter a protected area of your site without the proper credentials), 403 - Forbidden (as in when a file with permissions not allowing it to be accessed by the user is requested) and 400 - Bad Request, which is one of those generic kind of errors that people get to by doing some weird stuff with your URL or scripts. 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 This would cause any error code resulting in 404 to be forward to yoursite.com/errors/notfound.html Likewise with: ErrorDocument 500 /errors/internalerror.html You can name the pages anything you want (I'd recommend something that would prevent you from forgetting what the page is being used for), and you can place the error pages anywhere you want within your site, so long as they are web-accessible (through a URL). The initial slash in the directory location represents the root directory of your site, that being where your default page for your first-level domain is located. I typically prefer to keep them in a separate directory for maintenance purposes and in order to better control spiders indexing them through a ROBOTS.TXT file, but it is entirely up to you. 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 ErrorDocument ErrorDocument ErrorDocument 400 401 403 404 /errors/badrequest.html /errors/authreqd.html /errors/forbid.html /errors/notfound.html Successful Client Requests 200 OK 201 Created 202 Accepted 203 Non-Authorative 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

1 3

15/11/2011 10:19 ً

you may feel like 505 HTTP Version Not Supported skipping ahead. that should all be on one line. Colonel! The only time I use that HTML option is if I am feeling particularly saucy.error documents 2 ErrorDocument 500 /errors/serverr. believe it or not! ErrorDocument 401 "<body bgcolor=#ffffff><h1>You have to actually <b>BE</b> a <a href="#">member</A> to view this page. Also note that the ErrorDocument starts with a " just before the HTML starts. Redirects 10. but does not end with one.. But this is not the preferred method by the server's happiness standards. we are moving on to password protection.. /errors/notfound. Error Documents 3. since you can have so much more control over the error pages when used in conjunction with xSSI or CGI or both.com/errors /notfound.html). Prevent viewing of htaccess 11. And again.Comprehensive guide to . Change your default directory page 9. Enabling SSI via htaccess 5. Blocking bad bots and site rippers (aka offline browsers) 8. Adding MIME types 12. no naughty word wrapping! 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 Next. Blocking users/ sites by referrer 7. Preventing directory listing 14.it shouldn't end with one and if you do use that option. Tutorial Introduction 2.htaccess.html vs. that last frontier before I dunk you into the true capabilities of htaccess. Conclusion and more information Password protection 2 3 15/11/2011 10:19 ً . 1.html 410 Gone 411 Content Length Required You can specify a full URL rather than a virtual URL in the ErrorDocument string (http://yoursite. keep it that way. Password protection 4. Blocking users by IP 6. 412 Precondition Failed You can also specify HTML. If you are familiar with setting up your own password protected directories via htaccess. Preventing hot linking of your images and other file types 13.

3 3 15/11/2011 10:19 ً .Comprehensive guide to .htaccess. NO PART may be reproduced without author's permission.com/ddos_prevention.html Copyright © 1997-2011 JavaScript Kit.error documents 3 DDOS Prevention Avoid DDOS attacks Most reliable network DDOS solution apex-emea.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->