What if a link doesn’t work on your site? Mistakes happen, after all. Pages move, filenames change… it’s even possible that the user has typed in the right domain name, but completed the page name incorrectly.
The traditional response to this is the familiar "404 — Page Not Found" error, which is almost completely useless. Wouldn’t it be better to guide and inform the user? If they got close enough to get the domain right, they probably only need a nudge in the right direction to find the page they were after.
Fortunately, we can do just that. There is another special file, called the
.htaccess file, that functions as a “trap” for occasions like this. (It can also be used to make password–protected pages, among many other functions). Note that not all web hosting providers will allow you to create or modify an
.htaccess file is a plain text file. For our purposes here, it contains a single line:
ErrorDocument 404 notfound.html
In this case, the
.htaccess file is instructing the browser to find a page in the current directory called
"notfound.html" in response to a 404 error. All we have to do is create the
notfound.html page and upload it.
What should this page contain? Well, first of all, it should look somewhat like the other pages in the site. An almost–blank page will not help much more than the standard 404 browser error. Second, it should contain navigation to the most important areas of the site. A search form is often placed on the page, as is a link to the web site administrator (since if the user clicked on a link and ended up here, you should know about it). Aside from that, a 404 page can contain almost anything.
A custom 404 error page allows the user to find their way back into the site if they’ve fallen through a crack. It also lets them know that you care enough about them to put them back on track.