Creating a 404 (File Not Found) Page

EPA builds all web content in the Drupal WebCMS as of January 2013. All new microsites and resource directories will be created using Drupal.  There is still content on EPA's legacy servers and this content will be maintained there until it is transformed and moved into the Drupal WebCMS.  The following information should be used only for minor updates/maintenance of existing pages; any significant updates or revisions to existing pages should be done in the context of One EPA Web content transformation into the Drupal WebCMS

Note: These instructions are for Apache webservers in the shared environment.  If your content is in Drupal WebCMS, this information does not apply and you should NOT create a 404 page.

When a browser asks the server for a page that doesn't exist, the server generates a "404" error. EPA's site is set up to produce a default 404 page, as you can see by following this bad link:

The specification for 404 pages requires that each area use a custom error page. The following instructions explain how to create such a page. If your area is only one portion of a TSSMS, see the special note at the bottom.

Note: these instructions apply only to static HTML. For dynamically generated areas (e.g. those using Domino, Oracle, ColdFusion, etc.) use procedures appropriate to that environment.

There are five steps:

  1. Create a custom error page
  2. Upload the error page to the Web site
  3. Create a server configuration file (.htaccess)
  4. Upload the configuration file
  5. Test!

Create a Custom Error Page

  1. Develop the text you want to use. It is very helpful to provide people with suggested links (e.g., your home page, links to your most popular parts or pages, etc.), as well as an explanation of how common typos result in a bad URL. From the perspective of your reader, what would be most to helpful?
  2. Create an HTML file called 404.html with your information. This file uses normal HTML.
    • Note: all URLs in the file must be absolute, meaning they must start with "http://" and use the full address for each link - including sidebar and content links, recent additions, contact us (both at the top and bottom of the page), etc.
  3. Use your area's template. Even though that provides links to the contact page, it's helpful to provide an email address and a phone number in your error page.
  4. Invite the reader to send you the URLs for both the page containing the bad link and the bad link itself, either by providing an email address or using a form.
    • If you use this form, you must edit the hidden variables tssms, mailtofile, and Next so that reports are sent to someone associated with your area. Also change the last hidden variable to reflect your area's name.
    • Also provide a thank you page (see the example thank you page for ideas).
    • The form will send emails with one of three subject lines, based on whether a bad link occurred on a page on EPA's site or elsewhere, or someone typed an incorrect URL directly into the browser. Therefore, also change the subject line headings in the sample page's script (each of the three places where the subject line is set to begin with "Area Name:").
  5. Sample error pages (URLs intentionally mistyped):

Sample Error Page Content and Code

Note: this is a WORKING file not found page code. View and modify the source to generate the HTML for your area 404 page.

Upload to the Website

Upload 404.html to a web-accessible directory called auxfiles. For example, for EPAFiles, the 404 page is It resides inside the /adminweb/web/epafiles/auxfiles/ directory.

Create a Server Configuration File

Create a file called .htaccess (no extension; note the dot in front) on your local drive. If you have trouble, call it htaccess.txt and rename it when you upload it.

The file contains the one line shown below. All of the text must be copied exactly into the file, except for your_tssms, where you'll put your TSSMS name.

ErrorDocument 404 /your_tssms/auxfiles/error404.htm

In the EPAFiles example, this line says:

ErrorDocument 404 /epafiles/auxfiles/error404.htm

Note: if you already have an .htaccess file for other reasons, add this line to the end instead of overwriting the file.

Bad Example

Do not use an URL. Use the file system path. This syntax is NOT acceptable:

ErrorDocument 404

It corrupts the registration of the 404 error and causes our search crawlers real problems.

Upload the Configuration File

Upload .htaccess to your root directory. The root directory is where you keep your area home page. In this example, that's /adminweb/web/epafiles/.

If you created htaccess.txt, upload it and then rename it to .htaccess.


Go to a bad URL in your area. If your error page pops up instead of EPA's default one, you're done!

If you don't get your error page, make sure your .htaccess file is pointing to the correct location of your error page.

Special Note

If your area is smaller than an entire TSSMS, the directions above still apply, with the following changes:

  1. Put 404.html in an auxfiles directory within your root directory instead of the TSSMS root directory. For example, if the TSSMS is epahist1 and your area is contained in a directory called /epahist1/annivers/, your error page would be /epahist1/annivers/auxfiles/404.htm
  2. In .htaccess, include your directory in the path. In this example, the code would be: ErrorDocument 404 /epahist1/annivers/auxfiles/404.htm
  3. Put .htaccess in your area's root directory instead of the TSSMS root directory. In this example, it would be /epahist1/annivers/.htaccess

Top of Page