ASP 101 - Active Server Pages 101 - Web01
The Place ASP Developers Go!

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
What is ASP?
VBScript Classes: Part 1 of N
Migrating to ASP.NET

Using authorization headers
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Quick Tips

Response.Redirect vs. "301 Moved Permanently"

We've all used Response.Redirect at one time or another. It's the quick and easy way to get visitors pointed in the right direction if they somehow end up in the wrong place. But did you know that Response.Redirect sends an HTTP response status code of "302 Found" when you might really want to send "301 Moved Permanently"?

The distinction seems small, but in certain cases it can actually make a big difference. For example, if you use a "301 Moved Permanently" response code, most search engines will remove the outdated link from their index and replace it with the new one. If you use "302 Found", they'll continue returning to the old page.

The question now becomes, how does one actually send an HTTP response status code of "301 Moved Permanently"? While it's not as easy as doing a Response.Redirect, it's still pretty simple. Take a look at the following two lines of code:

    Response.Status = "301 Moved Permanently"
    Response.AppendHeader("Location", "")

Using this code instead of Response.Redirect will send a "301 Moved Permanently" HTTP response status code instead of "302 Found".

For more information on HTTP status codes, check out Wikipedia's List of HTTP Status Codes or, if you really want to get your hands dirty go ahead and read the section on redirection from RFC 2616 - Hypertext Transfer Protocol -- HTTP/1.1.

Update: ASP.NET Response.RedirectLocation

It appears that ASP.NET actually includes a Response.RedirectLocation property which you can set instead of using the AppendHeader method we originally used. The end result is the same, but based on the feedback we've received it seems that many of our readers prefer the RedirectLocation method.

The code is basically the same... just a slight syntax change:

    Response.Status = "301 Moved Permanently"
    Response.RedirectLocation = ""

Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to:

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers