Simple web design, web development, information technology, & technical communication

Articles and resources for web developers and the average person. Topics include web development, web design, technical writing and communication, and all aspects of information technology.

Redirect users to a new page with ASP

Originally published on Monday, October 10th, 2005

ASP makes it easy to redirect a user to another page. This is a useful trick for redirecting users after form submissions, protecting content on your site by redirecting users to a login page, and pointing an old page address to a new one.

Simple ASP header redirect (302 Object Moved)

At the top of your ASP document (before any HTML code), use the following code snippet:

<% Response.Redirect("default.asp") %>

This example shows how to redirect a user to a page on your own site, in the same directory as your redirect page. If you wanted to redirect a user to a completely different website, simply use the full URL:

<% Response.Redirect("http://www.yoursite.com") %>

The Response.Redirect declarative gives an “Object Moved,” or Status Code 302 header response. If you want to permanently point an old page address to a new one using ASP, see below.

Serving a permanent redirect (301) header status code

There may be an instance where you want to point an old page to a new location. This can be accomplished in ASP by including specific header information in your code snippet. The following example serves a 301 Redirect (“301 Moved Permanently”) to anyone who accesses the page.

<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.thenewpage.com"
%>

Add a Comment

You must be logged in to post a comment.

Articles By Category

Stay Updated