![]() |
![]() |
![]() |
Home -> Articles & Tutorials -> .htaccess -> Custom Error Pages
Tutorial -:- Custom Error Pages -Have you gone to a site clicked on a link and got a white page with '404 Error Page can not be found'Boring aren't they. Well you can use .htaccess to enhance your site by providing custom error pages. The best use of this is to generate a page with links back to your home page. If you want to create separate pages for all errors you need to know what the server is doing. When a web server can not deliver a page it generates an error code.
These are the standard codesSuccessful Client Requests 200 OK Client Request Redirected 300 Multiple Choices Client Request Errors 400 Bad Request Server Errors 500 Internal Server Error You do not need to specify error pages for all of these, in fact you shouldn't. If you created an error page for 200 it would create an infinite loop. The 404 is what people see when they either click on a link to a page that no longer exists or is incorrect. The 500 would help you out with internal server errors in any scripts you have running. You could put an email address on this page and ask users to report the error. In my experience most users won't report an error but at least you won't loose them as you have put a link back to your home page on the custom error page. Haven't you. :) 403 - Forbidden - This is where a file requested has permissions set that forbid access or the user supply's the wrong username or password. OK know you know a bit about what the server is going to do with each request lets start. To define custom error page first you have to build them. You should always put a link back to your home page or at least to you sitemap on your error pages. You have got a site map haven't you? This is the code that has to be inserted in to the .htaccess file. ErrorDocument code /directory/filename.ext Likewise with: 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 400 /errors/400.htm That's about it. Go to your site and type in a page that you know does not exist and you should get your new error page. If you are feeling up to we will now move on.
|
| Home :: Tutorials :: Online Tools :: Services :: Contact Us :: SiteMap © WWW Security Services 2004. Part of the Live Internet Entertainments Group of Website's. |