First time visitor? The tutorials start here.

Custom 404 Page Not Found Error Pages

So, you’re surfing the web, and you come across a page like this one:

Page not found

The page you are looking for might have been removed, had its name changed, or is temporarily unavailable. Please try the following:

If you typed the page address in the Address bar, make sure that it is spelled correctly.

  • Click the Back button in your browser to try another link.
  • Use a search engine like Google to look for information on the Internet.

HTTP 404 – File not found

What do you do? If you’re like most people, you might back out of it and move on to another website.

Don’t lose potential website visitors over something like this!

Instead, customize that error page and make it useful.

Note: The method outlined in this tutorial will only work if your host allows access to your .htaccess file. If you can’t find one or aren’t sure, I can set you up with hosting that does.

Creating the page

First, you’ll need to create your error page. It’s good to make it look like the rest of your site, then add things to it like a search box and a link to your site map. What is best for your 404 error page will depend on your particular website, but whatever you do with it, you should set it up so it makes it easy for people to find what they were looking for.

If you want something really advanced, you can even use server-side scripting to determine what keywords someone was searching for when they found your nonexistent page, and use those keywords to suggest links for the visitor to click on. Perhaps that will be a good topic for me to base a future tutorial on. But for now, let’s just get that page working for you.

After creating your custom error page, you can name it something like 404.htm or 404.php (depending on what you’re using throughout your site) and upload it to the root directory. Then, you’ll need to create or edit your .htaccess file.

Don’t overwrite a hidden .htaccess file

You may already have an .htaccess file that is hidden via FTP. Be careful when using FTP to upload your .htaccess unless (1) you can see it in your FTP software or (2) you know for a fact that you don’t already have an existing .htaccess file on your site.

If you do have an .htaccess file that you can’t see through FTP or you’re not sure whether one exists, you should be able to go into your hosting account’s web-based control panel and see it that way.

If one exists, save a copy of it on your computer, then open it with a plain-text editor such as Crimson Editor, Text Wrangler, or Notepad. Do not ever use a word processor to edit any kind of code, because word processors will reformat your characters and render the code useless.

If you don’t already have an .htaccess file, then open a new document in a plain text editor and save it as .htaccess — That’s a period (or full stop), followed by the word htaccess and nothing else before or after it.

Creating or editing your .htaccess file

Now, add this to your .htaccess file:

ErrorDocument 404 /404.htm

Remember, use the same file name (including the .htm, .php, etc extension) that you named it with.

Upload and test it

Upload your .htaccess file, then go to a nonexistent URL on your domain. If you did it correctly, you will see your new 404 error page.

That’s all there is to it, folks! 🙂

If you found this article useful, please spread the word:
Stumble it! Digg! Tweet it!

Questions or comments?

Please log in to post a comment. Sorry, but it prevents this from happening. If you're not registered yet, you can register here.