Visitors may try to load files in your directory which dont exist. This may be due to a bad link in your site, but more likely the error is located in a search engine or a link on an external site or elsewhere on MIA.
You need to capture that attempt and tell the visitor how to find the file they're looking for and give them the opportunity to tell you about it. This is done more effectively the closer to the destination of the non-existent file that you can capture the attempt.
An attempt to load a non-existent file will generate an error code 404 in the server. The server responds by searching up the directory tree until it finds a file called .htaccess (no extension). The .htaccess file is an ordinary text file which contains either of two types of redirection instruction.
Example 1: http://www.marxists.org/archive/marx/.htaccess:
ErrorDocument 404 http://www.marxists.org/archive/marx/404.htm
Example 1 redirects a client which tried to load any non-existent file in the directory or subdirectories to the local error-handler 404.htm
The 404.htm is an ordinary html document. See http://www.marxists.org/archive/marx/404.htm as an example.
This should contain the message explaining that the file was not found, links to indexes which you believe will reliably lead the visitor to any information in the relevant directory, and an email-button to the director.
Example 2: http://www.marxists.org/archive/marx/works/.htaccess:
Redirect /archive/marx/works/1840/com-man http://www.marxists.org/archive/marx/works/1848/communist-manifesto
Example 2 redirects a client which tried to load works/1840/com-man (an old file which has been relocated) to the directory works/1848/communist-manifesto.
Example 3: The same effect can be achieved by placing a redirect file in place of the redundant file.
To do this, an additional line of code must be placed in the header of an html file (http://www.marxists.org/archive/marx/works/1840/com-man/index.htm):
<meta http-equiv="refresh" content="0;URL='../../1848/communist-manifesto/index.htm'" />
The 0” here tells the client to wait 0 seconds before moving to the URL.