This page has been robot translated, sorry for typos if any. Original content here.

Error Handling 404 Not Found The requested URL



Imagine a situation: a visitor walks around your site, clicks on links, opens windows ... And suddenly - sees, in one - a message on the pale default background: Not Found
The requested URL /somepath/pivo.html was not found on this server.
Apache/1.3.X Server at www.some.net Port XX
Not Found
The requested URL /somepath/pivo.html was not found on this server.
Apache/1.3.X Server at www.some.net Port XX

This phrase, which speaks so much to a visitor without knowing English, is automatically generated by the server if a document is requested with the URL www.some.net/somepath/pivo.html, which is not on the server. Causes? The link is broken or the bookmark is out of date. Or the visitor typed the address manually and ochepyatka left. Or the beer was over ...

Especially polite webmasters in such cases do not like to frighten the user with a pale technical text, and create a .htaccess file in the server directory (if it is not already there), and put a line there: ErrorDocument 404 /path/error.html

And now the server, in all cases of error 404 ("document not found"), gives the visitor the error.html page prepared by the studious web designer. On this page, in a resource-style style, the authors apologize (which is worse than the whole links, but better than nothing), explain to the visitor that the requested page is not here and what to do about it now. For example, complain about a webmaster's email about poor service or go to the resource's home page. Some especially advanced insert on the same error.html a small search engine or site map ...

If your hosting allows you to use SSI (server-side includes) or php, you can not only apologize, but also remind the visitor what exactly "No beer" (if he, the visitor, has already lost his way in the open windows of your site and at point-blank range remembers from which page the link led him to "Error 404"). And ask him to send the webmaster an already prepared error message.

To do this, the file error.shtml (* .shtml - the standard file extension that will be processed by the server for SSI instructions) should contain: <p>Извините, пива марки &quot;<!--#echo var="REQUEST_URI"-->&quot;нет!</p> <p>Пишите в <a href="mailto:webmaster@some.net?subject=error404&body=<!--#echo var="REQUEST_URI"--> not found; link from <!--#echo var="HTTP_REFERER"-->">Книгу Жалоб</a>. Вебмастера уволят.</p> <p>Извините, пива марки &quot;<!--#echo var="REQUEST_URI"-->&quot;нет!</p> <p>Пишите в <a href="mailto:webmaster@some.net?subject=error404&body=<!--#echo var="REQUEST_URI"--> not found; link from <!--#echo var="HTTP_REFERER"-->">Книгу Жалоб</a>. Вебмастера уволят.</p>

The solution is using php (if it has a hosting provider): in .htaccess it is written

  ErrorDocument 404 /path/error.php 

In the body of the file is error.php (standard * .php files are processed for php-instructions), respectively: <p>Извините, файл &quot;<? echo $REQUEST_URI ?>&quot; не найден...</p> <p>Пишите в <a href="mailto:webmaster@ some.net?subject=error404&body=<? echo $REQUEST_URI ?> not found; link from <? echo $HTTP_REFERER ?>">Книгу Жалоб</a>. Вебмастер исправит.</p> <p>Извините, файл &quot;<? echo $REQUEST_URI ?>&quot; не найден...</p> <p>Пишите в <a href="mailto:webmaster@ some.net?subject=error404&body=<? echo $REQUEST_URI ?> not found; link from <? echo $HTTP_REFERER ?>">Книгу Жалоб</a>. Вебмастер исправит.</p>

In both (* .shtml and * .php) cases, the user will see an apology; and if it clicks on the link "mailto:", then in the window of its e-mail client there will be an already filled error message: what is not, where on this "what is not" link.

Notes : In principle, you can do nothing above. Let them learn English! ...