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 visits your site, clicks on links, opens windows ... And suddenly - he sees, in one - a message on a 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 from the URL www.some.net/somepath/pivo.html, which is not on the server. The reasons? Link broken or bookmark outdated. Or the visitor typed the address manually and ochepyatka left. Or the beer is over ...

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

And now the server in all cases of the 404 error (“document not found”) gives the visitor the error.html page prepared by the diligent web designer. On this page, in the corporate style for the resource, the authors apologize (which is worse than whole links, but better than nothing), they explain to the visitor that the requested page is not here and what to do about it now. For example, complain about the webmasters email about poor service or go to the main page of the resource. Some very advanced paste on the same error.html a small search engine or sitemap ...

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

To do this, the error.shtml file (* .shtml is the standard extension of files that will be processed by the server for SSI instructions) must 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>

Solution using php (if the hosting provider has one): in .htaccess is written

  ErrorDocument 404 /path/error.php 

In the body of the error.php file (standardly, * .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 he clicks on the mailto: link, then in the window of his email client an already filled error message will appear: what’s not, where does the link to this "what is not there".

Notes : Basically, you can do nothing listed above. Let them learn English! ...