Skip to the content of the web site.

Handling Replaced or Missing Pages

When you are updating your web site, you may find it necessary to replace some pages with pages with different names, or in different locations. But other web sites may have links to these older pages, and people may have these pages bookmarked. Printed material containing these URLs may also exist. You want to redirect references to the older replaced pages to the correct new ones. You also want to capture any references to missing but not redirected pages, and supply a helpful error page of your own, rather than leaving people with the standard browser "404 error" page.

These functions and more can be achieved by placing an appropriate file in the root directory of your web site. This file is called the .htaccess file. Note: an .htaccess file is only available on an Apache web server, which is the most commonly used web server on campus. Achieving similar function on an IIS web server will be discussed below.

The .htaccess File on Apache

The .htaccess file is not an HTML file, but a plain text file. It can be created with a text editor. Like all files in your web space, you must ensure that the Unix file permissions are set to be world readable.

Redirecting From a "pathed" URL to a Domain Name URL

Originally, many web sites were set up with a URL of the following format:

http://server.uwaterloo.ca/xyzdept

Then, many sites acquired domain names, so that the URL became:

http://xyzdept.uwaterloo.ca

This format is preferable, because it is meaningful, can be guessed at, and it makes it very easy to move a whole web site to a different location, even to a different server. However, there may be many instances of other web sites that have references to an old format of a URL, or people may have an old format bookmarked. There's not much you can do about the current links and bookmarks, but you can prevent any future links or bookmarks to the old pathed format by using your .htaccess file to redirect the old format to the new format. To do this, using the example above, you would place the following line in your .htaccess file.

Redirect   /xyzdept   http://xyzdept.uwaterloo.ca

This results in the web server redirecting URL requests that begin with http://server.uwaterloo.ca/xyzdept to
http://xyzdept.uwaterloo.ca.

For example, a URL of the form
   http://server.uwaterloo.ca/xyzdept/students/info.html
would be redirected to    http://xyzdept.uwaterloo.ca/students/info.html.

Redirecting Requests For a Specific Page to a Different Page

In updating your site, you may have consolidated or moved some files. You can redirect people who might have had such a file linked or bookmarked. Suppose the file called procedure.html that had been in the methods folder has been replaced by the file called howto.html in the functions folder. You would place the following line in your .htaccess file.

Redirect   /methods/procedure.html   http://xyzdept.uwaterloo.ca/functions/howto.html

You can place as many of these redirects as necessary in your .htaccess file.

Redirecting Requests For Missing Pages to an Error Page

Even with all your best efforts, you may forget to redirect a page you have replaced. If someone tries to load one of these missing pages, you would like to provide more information than is given by the browser "404 error" page.

You need to create a page in your site, and on that page place information explaining that the site has recently been re-organized, and the file in question no longer exists. Invite them to use the page's search box to locate the page, or to contact you via the link below. Suppose you call that page missing.html and place it in the errors folder. You would then add the following line to your .htaccess file.

ErrorDocument   404   /errors/missing.html

Complete .htaccess File

Our complete .htaccess file would resemble the following.

Redirect   /xyzdept   http://xyzdept.uwaterloo.ca
Redirect   /methods/procedure.html   http://xyzdept.uwaterloo.ca/functions/howto.html
ErrorDocument   404   /errors/missing.html

Line 2 will be repeated for each file requiring redirection.

Do You Have a Site Index

If your web site contains a site index, this may be an appropriate page to use as your 404 error redirect page.

Redirection on IIS Web Servers

IIS web servers such as Sumac and Dogwood do not have an .htaccess file. The functions of redirecting files, or specifying a "404 error" page can be achieved, but they must be done by the system administrator. If your web site is on Sycamore or Dogwood, please send email to request@ist and list the URL of each page that needs redirection along with the URL of the replacement page. Also specify the URL of your "404" error page.