Results 1 to 2 of 2

Thread: How to create a Custom 404 Error Page

  1. #1
    matthewforu Guest

    How to create a Custom 404 Error Page

    Every web surfer has encountered the dreaded 404 page not found error message.
    The generic error page is horrific to look at and it does not persuade web visitors to explore more of your site.
    Imagine being able to setup a custom error message page that looked good, told the visitor what had gone wrong and then suggested some substitute links to other locations on your site, such as the home page, sitemap or even a search page.
    If the visitor wanted to, they could then visit other parts of your site.
    It is very easy to setup a custom 404 error page (The 404 error is the error number returned when a page or directory is not found on your site).
    The easiest way to redirect visitors that encounter a 404 is to either send them to your sites home page or to your sitemap page
    We do this by placing a one line of code in your websites .htaccess file
    ErrorDocument 404 /sitemap.html
    This would redirect all 404 error messages to the sitemap page.
    The path to the page you want to display, must already exist on your web server, otherwise the web server will tie itself up in a never ending loop.
    The full path to the error page must be specified and it must be relative to the root path of that account (remember, placing a / at the front of a file name or directory specifies that it’s relative to the root directory).
    To make a custom error page, simply create a page using your preferred webpage editor such as MS FrontPage or DreamWeaver. The page can contain anything you wish, such as images, links etc. Save the file as something easy to remember (such as 404errors.html)
    I would then suggest you make a directory directly off your /public_html/ folder and call it “error” and place your error files in here.
    This would now mean that your .htaccess command line would now look like:
    ErrorDocument 404 /error/404errors.html
    Now whenever a 404 error was generated on your site, your custom error page will be displayed, and keep your web visitors happy.
    I will expand on this idea, and show you how to you can receive an email notification that a 404 error has occurred on your site. It will tell you what caused the error, and the offending page. Allowing you to try and fix all broken links leading to your site.

  2. #2
    Join Date
    Dec 2007
    Posts
    2,291

    Re: How to create a Custom 404 Error Page

    How to Set Up A Custom 404 File Not Found Page
    Let's do a quick survey: what do you usually do when you click a URL and encounter a "404 File Not Found" error? Do you:

    1. Click on the BACK button of your browser and go somewhere else?
    2. Try to back up one directory in the URL and try again?
    3. Write to the webmaster of the site and the referring site to inform them of the situation?

    If you are like most people, you'll simply click on the BACK button and try another place. The majority of people don't even know that there are any other alternatives.

    You thus need to do something so that you do not lose this group of people who come to your site by following an old link or by typing your URL incorrectly.

    Requirements for Customizing the 404 File Not Found Page
    It is not possible to customize your 404 error page if your web host has not enabled this facility for your website. For example, at the time of this writing, if you host at Geocities or Tripod, you would not be able to customize your 404 Error Page.

    If your web host has this facility, you will usually find mention of this somewhere in their documentation. In fact, if they mention somewhere that you can customize a file named ".htaccess", it probably means that you can also customize your 404 File Not Found error page.

    The .htaccess file is what Apache web servers use to allow you to fine-tune your web server configurations at a directory level. Other types of web servers handle the customization of 404 error pages differently.

    Step One: Creating/Modifying the .htaccess File
    This step may not be necessary in all situations. Some web hosts already configure their web server so that it will look for a specific file in your web directory when a certain document cannot be found. If so, simply skip this step.

    If your web server is not an Apache web server, you will have to find out from your web host what you need to do to enable the server to serve your customized file when a file cannot be found.

    Otherwise, the first thing you need to do is to add the following line to a file named ".htaccess" (without the enclosing quotes and with the preceding period). In most instances, no such file will exist, and you can simply create one with a text editor (such as Notepad on Windows).

    Code:
    ErrorDocument 404 /notfound.html
    You will of course need to put a notfound.html file in the main web directory for the above directive to work.

    The "ErrorDocument 404" directive essentially tells the Apache web server that whenever it cannot find the file it needs in that directory and its subdirectories, it is to use the document specified in the URL that follows.

    One .htaccess file in your main directory will do the trick for that directory and its subdirectories. However, if you want a certain subdirectory to show a different 404 File Not Found message, you can always place a .htaccess file into that directory. This will override any .htaccess files you have in the parent directories.

    More information here: http://www.thesitewizard.com/archive/custom404.shtml

Similar Threads

  1. Replies: 8
    Last Post: 06-05-2012, 12:21 PM
  2. How variables are attacked with a custom HTML page in PHP?
    By Leoniee in forum Software Development
    Replies: 5
    Last Post: 05-03-2010, 01:36 AM
  3. How to Create and use custom classes in VB 6.0?
    By Mr.ken in forum Software Development
    Replies: 4
    Last Post: 27-02-2010, 06:39 AM
  4. How to make custom bookmarks page in Mozilla Firefox?
    By Bharat89 in forum Technology & Internet
    Replies: 4
    Last Post: 26-12-2009, 07:27 PM
  5. How to create custom accelerator in XML
    By Broot in forum Software Development
    Replies: 3
    Last Post: 18-07-2009, 10:00 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,262,876.45462 seconds with 17 queries