by   October 03 2015   
When you need to redirect a page and need that redirect to be managed by an included page because of the site, size, type of redirects you need here is my code designed to transfer over and redirect based on anything your ASP Classic page can provide.

ASP Page Redirects done right forever. 

If you have a simple single page website you can simply redirect from your IIS server or the page.

But, if you are like many of us going on 20 years of ASP page creation you'll have hundreds if not thousands of pages that use all types of controls.

Example: xtremecomputer.com redirects to www.xtremecomputer.com
Example: www.xtremecomputer.com/1?a=1 redirects to www.xtremecomputer.com/1/default.asp

The list goes on.

Here's how I manage my redirects that date back 19 years.

My Included page.

<!--#inc_master_redirects.asp-->

If Len(Request.QueryString) <> 0 Then
   If Request.QueryString("y") <> "" Then
      strQS = Trim(Request.QueryString("y"))
      strQSID = "Y"&strQS
   ElseIf Request.QueryString("TOPIC_ID") <> "" Then
      strQS = Trim(Request.QueryString("TOPIC_ID"))
      strQSID = "T"&strQS
         If Len(strQSID) > 10 Then
            strQSID = Left(strQSID,10)
         End If
   ElseIf Request.QueryString("FORUM_ID") <> "" Then
       strQS = Trim(Request.QueryString("FORUM_ID"))
       strQSID = "F"&strQS
          If Len(strQSID) > 10 Then
             strQSID = Left(strQSID,10)
          End If
    ElseIf Request.QueryString("faq") <> "" Then
        strQS = Trim(Request.QueryString("faq"))
        strQSID = "FAQ"&strQS
            If Len(strQSID) > 10 Then
                strQSID = Left(strQSID,10)
            End If
    End If
End If

Select Case UCase(Trim(strQSID))

Case "Y1"
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "/community/developers-corner"
Response.End
Case "FAQ2"
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "/faq-and-help/posting-help"
Response.End
Case "FAQ4"
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "/faq-and-help/general-help/membership-faq/my-account-profile"
Response.End
Case "FAQ12"
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "/faq-and-help/"
Response.End
Case Else
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "/"
Response.End

End Select

 

From the code above you can see that I'm redirecting using a Select Case. 
This allows me to collect my old sites QueryString variable and then process it for my 301. 

What if I need to redirect based on Page Name?

Using the same format as above we can add the following code to the checks. 

I have placed it as a Function but you can add the code directly.

Function PageURL(sFile)
Dim sPageURL
sPageURL = Request.ServerVariables("SCRIPT_NAME")
If Not sFile Then
i = InstrRev(sPageURL, "/")
If i > 0 Then sPageURL = Left(sPageURL, i)
End If
PageURL = sPageURL
End Function

 

In this case I might use the following.

Dim strPageRedirect

strPageRedirect = PageURL(0) 

Select Case UCase(strPageRedirect)

Case "community/developers.asp"
Response.Status = "301 Moved Permanently" 
Response.AddHeader "Location", "/community/developers-corner" 
Response.End 
Case "faq.asp"
Response.Status = "301 Moved Permanently" 
Response.AddHeader "Location", "/faq-and-help/posting-help" 
Response.End 
Case "help/default.asp"
Response.Status = "301 Moved Permanently" 
Response.AddHeader "Location", "/faq-and-help/" 
Response.End 
Case Else
Response.Status = "301 Moved Permanently" 
Response.AddHeader "Location", "/" 
Response.End

End Select

 

It's really simple creating permanently redirects or temporary redirects when you are working on things. 

The key is to know when to stop redirecting. I put a number of years on redirects before I stop the code or shortening the list of redirects. 

If you have any questions feel free to ask. 

 

When you need to redirect a page and need that redirect to be managed by an included page because of the site, size, type of redirects you need here is my code designed to transfer over and redirect based on anything your ASP Classic page can provide.