Server-side redirects: .htaccess versus Meta Redirects - How .htaccess can help you: Custom Error Pages
(Page 2 of 6 )
Here are some common uses of the .htaccess file. These will allow you to have your own personal error pages (for example when a file is not found) instead of using your host’s error pages or having no page. This will make your site seem much more professional in the unlikely event of an error.
It will also allow you to create scripts to notify you if there’s an error. For example, you can create a JSP script on your own website to automatically e-mail you when a page is not found.
You can use custom error pages for any error as long as you know its number (like 404 for page not found, 403 for forbidden and 500 for server internal error) by adding the following to your .htaccess file:
ErrorDocument errorNumber /path/file.html |
For example, if I had the file not_found.html in the /errors directory of my site and I wanted to use it for a 404 error I would use:
ErrorDocument 404 /errors/not_found.html |
Another example is if I had made a JSP script that will automatically send me an e-mail notification when a server internal error has occurred on my site, and I put the script in the path: /utility/mailer.jsp, I would use:
ErrorDocument 500 /utility/mailer.jsp |
Additionally, you can use an external page to customize your error. For example when you found a 404 Not Found page on Yahoo, and you wrote down the URL: http://www.yahoo.com/errors/404.html, you would modify your .htaccess file content as follows:
ErrorDocument 404 http://www.yahoo.com/errors/404.html |
With this code, when a bad request comes to your website, it will be navigated to http://www.yahoo.com/errors/404.html
Next: Password Protection / Authentication >>
More JavaScript Articles
More By Stephen Davies