Custom 404 Pages
Something I found surprisingly difficult to find on the net is how to add custom 404 pages to your main and sub domains. A lot of people are scared of customising their pages due to the complicated nature of regular expression matching and .htaccess files.
So, what are 404 pages? If you try to browse to a non-existent page, this will cause a 404 error on the server and you will be directed to a 404 page. The problem arises for some when the server redirects your visitor to a 404 page they want to see rather than the one that you want. Take a look at a hostgator 404 page:
Not pretty, is it? This is a clever way for hostgator to make money on your sites and even direct traffic away from your site. Read on to see how to create your own custom 404 page and keep visitors at your site.
You will nees file access to your sites root directory. After you browse to this directory you will see a file named .htaccess. If you use a putty client to log in, use the ls -al command not ls -l to view the file.
Open the .htaccess file for editing and add the following code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yoursite.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.yoursite.com/directory$
RewriteRule ^(.*)$ "http\:\/\/www\.yoursite\.com\/directory" [R=301,L]
ErrorDocument 404 http://www.yoursite.com/directory/404.shtml
Don’t worry about the code too much. For now just change the “yoursite.com” and “directory” to match your site and directory of the root of your site. Leave the directory out if your site is installed in the root of your server.
Notice the last line of the code has the path to the 404 file. Now, create a file called 404.shtml, and add your 404 text, e.g. ‘File not Found’. And that’s it! To test, browse to a non-existant page on your site and you should see the text you entered in the 404.shtml page. It’s a bit bare, but you can now customise it to suit the look and feel of your site.


Write: ErrorDocument 404 /404.shtml in your .htaccess file and then create a file called 404.shtml in your public folder.. Much easier..
(And then edit the 404.shtml file…)