404 Error Page Code Htaccess
Contents |
Articles Code Recommended Most Popular .htaccess Error Documents for Beginners Apache allows you to customize the server at the directory level, using .htaccess files. This tutorial explains how to use them to serve custom
Custom Error Pages Htaccess
404 error (page not found), and other common error pages, to your users. set 404 error page in htaccess In Apache, you can set up each directory on your server individually, giving them different properties or requirements for
404 Error Page Redirect Htaccess
access. And while you can do this through normal Apache configuration, some hosts may wish to give users the ability to set up their own virtual server how they like. And so we redirect 404 error page using htaccess have .htaccess files, a way to set Apache directives on a directory by directory basis without the need for direct server access, and without being able to affect other directories on the same server. One up-side of this (amongst many) is that with a few short lines in an .htaccess file, you can tell your server that, for example, when a user asks for a page htaccess 403 error that doesn't exist, they are shown a customized error page instead of the bog-standard error page they've seen a million times before. If you visit http://www.addedbytes.com/random_made_up_address then you'll see this in action - instead of your browser's default error page, you see an error page sent by my server to you, telling you that the page you asked for doesn't exist. This has a fair few uses. For example, my 404 (page not found) error page also sends me an email whenever somebody ends up there, telling me which page they were trying to find, and where they came from to find it - hopefully, this will help me to fix broken links without needing to trawl through mind-numbing error logs. [Aside: If you set up your custom error page to email you whenever a page isn't found, remember that "/favicon.ico" requests failing doesn't mean that a page is missing. Internet Explorer 5 assumes everyone has a "favicon" and so asks the server for it. It's best to filter error messages about missing "/favicon.ico" files from your error logging, if you plan to do any.] Setting up your htaccess file is a piece of cake
be getting into progressively more advanced stuff after this. 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
Htaccess 500 Error
Multiple Choices 301 Moved Permanently 302 Moved Temporarily 303 See Other 304 Not Modified how to make custom 404 page 305 Use Proxy Client Request Errors 400 Bad Request 401 Authorization Required 402 Payment Required (not used yet) 403 Forbidden 404 Not
Errordocument 404 Htaccess
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 https://www.addedbytes.com/articles/for-beginners/error-documents-for-beginners/ 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 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 http://www.javascriptkit.com/howto/htaccess2.shtml 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
you click a link and encounter a "404 File Not Found" error? Do you: Click on the http://www.thesitewizard.com/archive/custom404.shtml BACK button of your browser and go somewhere else? Try to back up one directory in the URL (ie, web address) and try again? Write to the webmaster of the site and the referring site to inform them of the situation? If you are like most people, you'll simply click on the BACK button and try another place. The majority of error page people don't even know that there are any other alternatives. You thus need to do something so that you do not lose this group of people who come to your site by following an old link or by typing your URL incorrectly. Requirements for Customizing the 404 File Not Found Page It is not possible to customize your 404 error page if 404 error page your web host has not enabled this facility for your website. For example, at the time of this writing, if you host at free web hosts like Geocities or Tripod, you will not be able to customize your 404 Error Page. Commercial web hosts, on the other hand, usually provide this facility. If your web host supports a way to customise your 404 file, you will usually find mention of it somewhere in their documentation (or advertisements). In fact, if they mention somewhere that you can customize a file named ".htaccess", it probably means that you can also customize your 404 File Not Found error page. The .htaccess file is what Apache web servers use to allow you to fine-tune your web server configurations at a directory level. Other types of web servers handle the customization of 404 error pages differently. (A web server, in this context, is the software that runs on your web host's computer. It is the program that "serves" your web pages to your visitors.) Step One: Creating/Modifying the .htaccess File This step may not be necessary in all sit