Our ASP application is moving to a new server and I want to implement a permanent URL redirection. I am aware of the following two approaches, but I need to understand which one to use and when.
Option 1:
<%@ Language=VBScript %><% Response.Redirect "http://www.example.com" %>
Option 2:
<%@ Language=VBScript %><% Response.Status="301 Moved Permanently"
Response.AddHeader "Location",开发者_如何学运维"http://www.example.com/" %>
Thanks,
Nikhil.
Response.Redirect issues a 302, which is a temporary redirect. 301, using the Response.AddHeader that you listed, is for permanent redirects.
The differences between 301 and 302 have some importance with search-engine-optimization. A 301 will hold all of your search rankings from the old location. On the flip side, if you DON'T want your new page to be indexed, you can use a Response.Redirect (302) since the engines will consider the redirect temporary. Google doesn't index 302's because a lot of spammers use it to try to increase their rankings.
Since you're permanently moving to a new server, a 301 is the best way to go.
Response.Redirect()
(and the equivalent method RedirectPermanent()
for a 301) does a lot of things behind the scenes. It null checks the requested URL string, encodes it, calls the event handlers for the Redirecting
event if there are any, and finally calls Response.End()
, which flushes the response back to the browser and aborts the current thread.
Ultimately, you probably won't notice much difference between setting headers manually and calling redirect.
Incidentally, there are more (and better) options for handling this. IIS has a URL Rewriting module, which would let you redirect a given URL without ever calling your page as a request handler, and centrally manage your URL's for easier management of search engines.
A normal redirect will by default use HTTP status 302. A redirect with status 301 will not be indexed by searchbots (like Googlebot) and if they were, they will be removed from existing indexes. Very useful if you want to "update" an old URL to a newer URL. The searchbot will index redirects with status 302 anyway, so you may likely end up with pollution in search results. You'd normally use status 302 for for example PRG pattern and status 301 for permanent redirects like as you're doing now.
Response.Redirect sends a "302 - moved temporarily" status code to the browser, which may or may not be okay depending on what you are doing. If you are redirecting to the correct location for your content, you want to do the 301 redirect because search engines will not crawl properly against a 302.
精彩评论