DreamweaverFAQ.com
Search the site!Search DWfaq.com | Print This PagePrinter Friendly Page
Current: Default | Default: typical turtle


DreamweaverFAQ.com » Tutorials » Miscellaneous » Custom Error Pages


Q. How can I stop my site from returning the default 404 page not found error?

A. You will need to create a custom error page. Depending on whether your site is hosted on a UNIX server or an NT server, follow the steps in the tutorial below.

Never Have a 404 Page Not Found Error Again

Unix or NT server

If your website is hosted on a UNIX server you can create a 404 error trap yourself that will redirect all code 404 errors (page not found) to your opening page, just follow steps 1 and 2 below. If your site is located on an NT server, instructions to make the necessary changes are available from the Microsoft NT workshop. Set the NT 404 error to call a file named 404redirect.html, then continue to step 2 below. If you are not the administrator of the NT server you will have to ask someone to make these settings as they need to be done at the physical server level.

Step 1 - For a UNIX Host only

  1. Open Notepad and Create a new text file.

  2. Enter the following one line in it:
    ErrorDocument 404 http://www.your_site_name.com/404redirect.html
  3. Replace your_site_name.com with the actual name of your web site.
    Note: All references must be absolute paths.

  4. Save this Notepad file as “.htaccess” (it starts with a period and has no extension and is enclosed in quotes).
    Note: You must enclose the file name with quotes or change the Notepad option of Save As Type Text Documents (*.txt) to All Files before saving a file without an extension. Save this file in your site's root directory where your index.html page is located. If you already have a .htaccess file, add the ErrorDocument line to it.

Step 2 - UNIX or NT Host

In Dreamweaver open a new file. Save it in your root directory and name it 404redirect.html. Make it as plain and simple as you can. No fancy banners, colors, or options. You want it to load quickly as it will only be displayed for 5 seconds before taking the site visitor to your opening page. Enter the following text (or something similar to it):

The page you requested is no longer available or has been moved.

If you entered this site by a bookmark, please update your bookmark.

You will be taken to the site opening page within the next 5 seconds.

If not click this Link

Highlight the last line of text and create an absolute link to your opening page. An absolute link is http://www.your_site_name.com/index.html. This is an absolute reference link to your opening page. Again: change your_site_name.com to the real name of your site and don’t forget the http://www and the index.html.

This is just a safety feature to assure that the visitor stays and if they get tired of waiting the 5 seconds they can click the link and get going.

Remember: All references made in your 404redirect.html and .htaccess files must be full absolute paths. (http://www.your_site_name.com/index.html)

Place this META refresh and JavaScript redirect code in the <HEAD> of your 404redirect.html page:

<META HTTP-EQUIV = "Refresh" Content = "8; URL =http://your_site_name.com/index.html"> 
<META name="robots" content="NOINDEX, FOLLOW"> 
<script language="JavaScript"><!-- 
setTimeout("top.location.href = 'http://your_site_name.com/index.html'",5000); //-->
</script>

This redirect code is a javascript time-out redirect set at 5 seconds. If the visitor has javascript disabled or they have an older browser that does not support javascript the META refresh redirect will take over at 8 seconds. The use of a script redirect set to activate before the META redirect should satisfy most search robots better than a META redirect alone will. Some robots will not index past a META redirect.

Your .htaccess text file and the 404redirect.html file must be located in the root directory of your hosted website. This is the same location where you keep your index.html file.

You will never have a code 404 page not found error again no matter how many pages you move, change the names of, or just forget to upload. All 404 page not found errors will be redirected to your opening page automatically. If you want to eliminate the courtesy page telling the site visitor to change their bookmark you can enter the URL for your index.html page directly in the .htaccess file instead of calling the courtesy 404redirect.html page. I do not like to do this as it is always nice to inform the visitor why the page they requested is not displayed before taking them to another page.

You will not be able to test this redirect on your local machine. The files you created need to be uploaded to your server's root directory before they will work.

Related tutorials

Introduction to META tags
by turtle
URL: http://www.dwfaq.com/Miscellaneous/intro_to_metas.asp

Additional Reference and Resources

Free Webmaster Help
URL:http://www.freewebmasterhelp.com/tutorials/htaccess/

Webmaster's Guide
URL: http://www.webmastersguide.com/htaccess-cgi/htaccess.htm

Big Nose Bird
URL: http://bignosebird.com/carchive/birdtrap.shtml

Oregon State University
URL: http://www.orst.edu/aw/faq/htaccess.htm

Amateur Coalition
URL: http://amateurcoalition.com/masters/guides/programming/htaccess.html

::This page last modified 8/13/2013 at 09:37::

Copyright © 2001-2017 DreamweaverFAQ.com All Rights Reserved.
All brands, trademarks, tutorials, extensions, code, and articles are the property of their respective owners.
A production of Site Drive Inc.
Legal Notice | Privacy Policy | Disclaimer & Notice