How to make a custom 404 page

How to make a custom 404 page

You can achieve a lot of things with a .htaccess-file. You can make your own custom 404-error pages, redirect pages, rewrite pages, block IP-adresses and more. In this first .htaccess tutorial, I will explain the custom error pages.

How to make a .htaccess file

A .htaccess file is very easy to make. I always use Notepad to modify it. But you have to pay attention when you save the file. .htaccess is the extension of the file, not the name. The file must no be for example .htaccess.txt but just .htaccess . The .htaccess file must be uploaded to your root folder to make everything work.

Custom 404-error page

It is not hard to make you own custom 404-error page with .htaccess. First make a new file. This will be your error page. For example call it 404.html and place it in your root directory. There are loads of articles about “the perfect 404-page”. Some things include: adding a search box so people can search the site for what they were looking for, adding a e-mail adress to contact the webmaster, etc. There are nice articles about this on A List Apart and Coding Horror. This is what you have to place in your .htaccess file in our example:

ErrorDocument 404 /404.html

This is only the 404 error, but there are loads of errors that you can make custom pages for. A list:

  • 302 - Redirect
  • 400 - Bad Request
  • 401 - Authorization Required
  • 402 - Payment Required
  • 403 - Forbidden
  • 404 - File Not Found
  • 405 - Method Not Allowed
  • 406 - Not Acceptable
  • 407 - Proxy Authentication Required
  • 408 - Request Time-out
  • 409 - Conflict
  • 410 - Gone
  • 411 - Length Required
  • 412 - Precondition Failed
  • 413 - Request Entity Too Large
  • 414 - Request-URI Too Large
  • 415 - Unsupported Media Type
  • 500 - Internal Server Error
  • 501 - Method Not Implemented
  • 502 - Bad Gateway
  • 503 - Service Temporarily Unavailable
  • 504 - Gateway Time-out
  • 505 - HTTP Version Not Supported

I’ll write more .htaccess tutorials soon.

This entry was posted on Monday, February 18th, 2008 at 4:47 pm and is filed under .htaccess, Other. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Comments
  1. akbar Says :
    1

    i want add my weblog

  2. Tyler Williams Says :
    2

    I found your site courtesy ozzu.com forum. I really like it.

    I run a brand new human-edited directory and we’re looking for a base of quality link exchanges to get us off to a good start. I surfed a while and found this. I wanted to persuade you into submitting to our directory, free completely w/ a reciprocal link (place it anywhere non-intrusive, even next to a copyright notice). I’ll inform my editors to look out for onyx-design.net. http://www.xe03.com/submit.htm

    thanks
    xe03.com webmaster

    Link and advertising removed -admin
  3. admin Says :
    3

    @akbar, you mean adding it to your own weblog? What is your blogging platform?

    Wordpress has a 404 page by default, you can customize it by editing the 404.php file in your theme directory:
    /wp-content/themes/YOURTHEMENAME/404.php

    @Tyler Williams,
    Thanks for the compliment, but please do not promote your own website here. Contact me instead.

  4. Paintworkz Web Design Says :
    4

    Hi
    I would like to thank you for the information provided on .htaccess file. And looking forward to more post on this topic.

Trackbacks
  1. Redirecting with .htaccess | Onyx Design Weblog

Leave a Reply