301 Page permanently moved

When rewriting this website as ASP .net I had a lot of external pages linking directly to articles using the old ASP URL.  I wanted to be able to display the article based on these old URLs, but still let Google know that the page no longer existed.

The solution was to look up the old article ID in a table, if found I would return a "301 Page permanently moved" code, and if not found I would return a "404 not found" code.

First I open a connection + create an SQL select statement (not shown).  I then set Response.Status to the appropriate code.  If the code is "301" then we also need an additional header named "Location" which holds the new URL.

set rsArticle = cnnConnection.Execute(sql)
if not rsArticle.BOF and not rsArticle.EOF then
    dim NewUrl
    NewUrl = rsArticle("ArticleId")

    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location", "http://www.howtodothings.com/ViewArticle.aspx?article=" & NewUrl


else
    Response.Status = "404 Not Found"
end if

 

Share this article!

Follow us!

Find more helpful articles: