ASP 301 - Moved Permanently

Audience Level

Beginner and above

Instructions

A very simple wrapper function to send clients a HTTP 301 status code under ASP (JScript) but easily adapted for other ASP languages. ASP has no built-in function for performing a 301 and “Response.Redirect” only sends a 302 to the client. However, a 302 means “the resource you requested is temporarily available at this other URI” and is often used incorrectly leading to interesting results with search engines. The 301 status indicates to the client that it should not look for the resource in the old location again since it has permanently moved to the new specified location.

Invoke as “doPermanentRedirect(strDestinationUri)” where “strDestinationUri” is the address of the page or resource that the client should retrieve instead of the current page URI. If the function fails in some critical way it will throw an exception so JScript users should be prepared to “catch” this.

Source Code

function doPermanentRedirect(strDestinationUri) {
    Response.Clear();
    Response.Status = 301;
    Response.AddHeader("Location", strDestinationUri);
    Response.End();
}

Note

strDestinationUri” should be an absolute URI for maximum client compatibility. The function assumes that “Response.Buffer = true;” has been set at some point prior to invoking the function and will error if hasn't (this is the default configuration for IIS5 and above).

Advertisement

Feedback

Voting Panel
Could this be improved?
or
Did you find any bugs?
or
Rate this script: (0 = poor, 5 = very good)
Answers are anonymous, only the combined totals are stored. Uses cookies.