Tuesday, August 18, 2009

Create custom error pages with htaccess

Create custom error pages with htaccess Have you ever noticed that some people are really nice error pages when a page does not exist on your site? Would not it be nice if you could make your error page match the rest of your site? Do not worry, you can do it! All you have to do is to use a 'hand-file called. htaccess. The first thing to know is which. Htaccess is a very powerful file that controls many important parts of your site. Before changing anything, make sure you make a backup copy. If something goes wrong, you can retu to the backup. If there is already one. htaccess on your server, you can create one in Windows Notepad or your favorite HTML editor. If you use Windows, make sure you save the file as ". htaccess "including the quotes. Then you need some HTTP response codes. What are these, you ask? Well, every time you access a page on your browser, the server that contains the page (or is thought to contain the page), the search for the page and sends a numeric code back to the browser. If all goes well, the server sends back code 200 for you and the page is displayed. If the page is not found, the server sends a retu code 404. That is why the error page not found errors are commonly called 404. There are many different codes HTTP, but it is only necessary to make the pages for some of them: 400: Bad request. The server can not understand the request to send. E 'rarely (hopefully). 401: request for authorization. To access this page, you will need a useame and password. 403: Forbidden. The server has been instructed to refuse the request. 404: Page not found. Our friend the 404 error. You can use this page more often. 408: Timeout. The request could not be completed within the time allowed for this. Your browser will automatically generate a message when this occurs. 500: Inteal error. There is something wrong with the server. This is usually caused by problems with the script or your. htaccess. Ok, now is a little 'to understand what. Htaccess can do, we are ready to start doing the grunt work. The first thing we should do is to make our error page. You can make a different page for each type of error or an error page. The choice is yours, but we will do a 404 error page in this tutorial. Go ahead and put some HTML on your page, and feel free to spice it a little '. In fact, until spices. Use the style sheet that fits your site. Insert a link to your homepage. Register your e-mail so that people can contact if a problem occurs. (If you're worried about spam bot, you can hide your e-mail.) Once your done, save the page as an HTML file. Please call our error404.html and save the file in the / errors. Once you're done, it's time to do the magic. Open the. htaccess you have found / created. If yours is Premade, find an empty space at the base. Now, insert the following line of code: ErrorDocument 404 / errors/error404.html That's it! If you want to add more error documents, just add more lines ErrorDocument. The format of the line ErrorDocument HTTP_error_number / path / to / errorpage.ext If you want to be really fancy, you can use your name CGI, PHP, ASP or other pages, as your error page. Now, some kind of random to go to check the URL of your bookmarks mistake it! Want to know more about. Htaccess? Visit ml

No comments:

Post a Comment