I needed a way to redirect old and broken links, which Google Webmaster complains I have about 30, on external sites to correct pages on a site I manage that is a classic ASP site. There’s tons of posts on how to do URL rewriting for Classic ASP sites. After a bit of research, I’m pleased with the method I’m using.

This fellow here gave me the basis for what I did. Thanks, John!

First, shared IIS host most likely means that a) you don’t have access to the IIS management console, b) your web hosting service does expose a means whereby you can establish your own http error pages. Point b will help us get around point a. (I’d much rather handle this server-side, by the way)

Set up an error page. I’ve used this path off root: /error/http-redirect.asp. I’ve linked the 404 error page as provided by the host to this page. Set your page up as you would any 404 page, I used the advice from the ever-trusty A List Apart’s “The Perfect 404″ reference for that.

Next, add a script like the following to the top of your page. The fun is in the if/elseif statements. This is where you can add all broken URLs and redirect them to new, working paths.

<%
' John's original script called for QUERY_STRING although
' here, our URLs don't have this appendage, so we look
' for the HTTP_X_ORIGINAL_URL
strQuery = Request.ServerVariables("HTTP_X_ORIGINAL_URL")
strPage = Mid(strQuery, InStrRev(strQuery, "/") + 1)

' this item is sorted from most to least hit missing pages
' Spookora redirects was at 100
If strPage = "spookora.asp" or strPage = "sporkora.asp" Then
 Response.Status="200 OK"
 response.redirect("/products/sporkora.asp")
' spookora catalog was at 46 hits
ElseIf strPage = "spookora-cat.pdf" Then
 Response.Status="200 OK"
 response.redirect("/products/catalogs/spookora-cat.pdf")
Else
 'Put your normal error page here, so far I haven't used this statement
End If %>

Add ElseIf statements like the above to add as needed. Then be sure to test that the redirects work as expected.

While we’re at it, another page that is a help for those of us supporting legacy code is here, which adds a simple print() and break() classic asp function so you can see your variables.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Performance Optimization WordPress Plugins by W3 EDGE