404 errors and 404 headers
I was working on one of my other websites over the weekend and decided to customize the 404 not found error page. There are a lot of reasons to do this, but mine was the fact I had re-organized some of my content and wanted visitors to find my main page. Have you ever done this with apache? Here’s how I did it.
First, open your text editor and create a file called “.htaccess”. this file tells the apache webserver how to handle page requests and some other stuff.
On one line, enter the following text:
ErrorDocument 404 /404.shtml
Here’s what this line means. ErrorDocument tells apache you’re manipulating a response to an error message. The 404 indicates which error you’re manipulating. The /404.shtml tells apache to return the 404.shtml page from the root folder of your site for any 404 error it encounters.
Now, save the .htaccess file and upload it to your site’s root directory. Use your text editor or page design tool to create and save the 404.shtml page your .htaccess file refers to, and upload it to the root of your site as well.
An important part to remember is the part of the .htaccess file that specifies which file to return for the error. Above, this is “/404.shtml”. Notice I didn’t use “http://www.mysite.com/404.shtml”. The reason for this is that the http link to the file would not return the correct headers (page request information passed to the browser) when a 404 error should have been encountered. It would have returned a 200 OK message instead, which could confuse site spiders and search engines.