Create a .htaccess file to redirect to a 404.html page

Written by on June 21, 2010 in Coding - 1 Comment
404

A 404 error is what happens when you try to access a page on a website that doesn’t exist. We’ve all gotten them; due to typos, a moved file, whatever the case. As designers / developers we need to make sure we help the users of our websites should this happen to them. The last thing we want is for them to get an ugly 404 error, get discouraged, and exit your website.

Instead, you want to create a custom 404 webpage, and redirect the user to this page should the error happen to them. This is done by uploading a .htaccess page to the root of your website.

Simply create a text document named htaccess in any text editor, and copy past the following code.

<IfModule mod_rewrite.c>
RewriteEngine On
ErrorDocument 404 /404.html
</IfModule>

What that code is doing is redirecting the user to 404.html. Obviously you can name the page anything, just make sure to change the code. Upload the file, put a dot in font of the name ( so it’s .htaccess ), and you’re all set. Go to your site and type in a page that you know doesn’t exist. You should be re-directed to your new 404.html page.

Speaking of your new 404.html page, make sure when you create it you help the user along. Check out the 404 page I made for my website, BeantownDesign.com

Beantown Design 404.html page

You can see it’s rather simple, but I point the user to the three things I consider to be the most important on my site: my home page, my portfolio, and of course my contact page. You can do whatever you want, just make sure you are making your user’s life easier.

Here is a htaccess file you can download and use.

Download File

About the Author

Mike Ilsley "ilz" is a Boston based website designer, front-end developer, WordPress addict, owner of Beantown Design, and exclusive ThemeForest author. Check him out on Twitter, Facebook, Google+ and don't forget to subscribe to the WebDesign&Such email RSS feed. Also, check out his latest project, jQueryMobileShowcase.com.

  • sajol

    Hi, i have used the .htaccess file. this is a good idea to get more failure traffic to back website. thanks for the information.

    make money online