Access Keys:
Skip to content (Access Key - 0)

Web Publishing - Theme your 404 error page

A 404 ("file not found") error occurs when a visitor to your website tries to access a page that does not exist. If your site is hosted on web.mit.edu, you can customize the look and feel of this error message to fit with the rest of your website.

Custom 404 error pages

Providing a custom 404 page that includes your identity, main navigation links to your site, and a search box will help visitors find what they are looking for.

Example

file not found


I'm sorry /web/reference/web-resources/404.shtml cannot be found. It may have been removed, had its name changed, or is temporarily unavailable.

  • If you typed the URL, check the spelling
  • Start from the [your site here] home page and look for links to the information you want.
  • Click the back button and try another link. Please report the bad link to the page owner of the previous page.
  • Search our website using the form below. Search [your site here]
    If you still can't find the document you're looking for please contact [your department name]. HTTP 404 - file not found

Use the code

Select the code below, copy it into a new page using your favorite text or HTML editor. Customize the website name, links, and contact information. Save the page as 404.shtml in a folder named "errors" in the root of your website.

<\!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>404 error: file not found</title>
<style type="text/css"> body {font:Arial, Helvetica, sans-serif;} #content {margin-left:32px; margin-top:5px; width:90%;} </style> </head>
<body>
<div id="content"> <a href="http://web.mit.edu/index.html"><img src="/sites/default/files/migration/web/reference/images/mit-hdr-logo.gif" alt="MIT home page" width="357" height="46" border="0" /></a>
<h1>file not found</h1> <hr />
<p>I'm sorry <strong>http://web.mit.edu<\!--#echo var="REQUEST_URI" \--></strong> cannot be found. It may have been removed, had it's name changed, or is temporarily unavailable.</p>
<ul>
<li>If you typed the URL, check the spelling</li>
<li>Start from the \[istdraft:<a href="#">your site here</a>\] home page and look for links to the information you want.</li>
<li>Click the <a href="/web/reference/web-resources/javascript:history.back(1);">back</a> button and try another link. Please report the bad link to the page owner of the previous page. </li>
<li>Search our website using the form below. </li>
</ul>
<form name="search" id="search" action="http://search.mit.edu/query.html" method="get">
<p>Search \[istdraft:your site here\]:
<input type="hidden" name="qp" value="url:mit.edu/" />
<input type="text" name="qt" />
<input type="submit" name="Submit" value="search" /> </p>
<hr />
<p>If you still can't find the document you're looking for please <a href="#">contact \[istdraft:your department name\]</a>. </p> <p>HTTP 404 - file not found</p>
</form>
</div>
</body>
</html>

You can also use an HTML page, but you won't be able to display the URL that the visitor was trying to find.

Important: All image and link paths need to be absolute (e.g., /web/reference rather than ../reference). If the paths are not absolute the error page will not display or link correctly.

Interacting with the MIT web server

When the server can't find the URL requested it looks for a .htaccess.mit file located in the root of your website. This text file should include the following line: ErrorDocument 404 /afs/athena.mit.edu/your_websites_path/errors/404.shtml
This file tells the web server that you have a custom 404 page. This is the same file that restricts access to web pages via MIT certificates. Both of these instructions can co-exist in the same file.

Use and test

Make a directory at the root of your website called "errors". Name your custom 404 error page "404.shtml" and upload it to the errors folder. Upload the .htaccess.mit to the root of your website or the directory for which you would like the custom 404 error page to be displayed.

After you've uploaded these two documents to your site, remember to test it. Go to nonexistent pages in all the directories of your website.

IS&T Contributions

Documentation and information provided by IS&T staff members


Last Modified:

January 10, 2013

Get Help

Request help
from the Help Desk
Report a security incident
to the Security Team
Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
Feedback
This product/service is:
Easy to use
Average
Difficult to use

This article is:
Helpful
Inaccurate
Obsolete
Adaptavist Theme Builder (4.2.3) Powered by Atlassian Confluence 3.5.13, the Enterprise Wiki