001114-3

If a user asks for a web page at a certain URL, but that page is no longer stored at the indicated URL, the web browser can automatically download the right web page from another URL. How can this be specified using (a) HTTP commands or alternatively (b) using HTML commands.

Answer

Method 1: HTTP Redirect (2). The web server responds with the return code "301 Moved Permanently" (1) and the "Location:" (1) field indicates the new URL. Modern web browsers will then automatically get the document fromthe new URL.

Example:

HTTP/1.1 301 Moved Permanently
Location: http://foo.bar.net/new.html

Method 2: Include, in the <HEAD> of the HTML file, a refresh command (2), Example (1):

<META HTTP-EQUIV="Refresh" CONTENT="0; URL=http://foo.bar.net/new.html">

Method 3: Use Javascript (2). Example:

<BODY onload="window.open('http://foo.bar.net/new.html/','_self')">

Method 1 is faster, since method 2 and 3 has to show the referral page before loading the new window content.

List of exam questions