My site INeedCoffee was first built way back in 1999 using Classic ASP. Back then it was just called ASP or Active Server Pages. It works well and doesn’t require moving to ASP.NET, so I never updated the code base. If it isn’t broke, don’t fix it.
There was one thing I wanted to address better recently and that was how I handled incoming broken links. I used to just redirect every request to the home page, but I’ve since learned that 404 error codes are OK to have. If the page is missing, returning a 404 code is appropriate.
When I studied the bad incoming links, I isolated about 15 where I could tell what article was intended in the link. For these links, I wanted to give a 404 error and provide a suggestion on what page is most likely the correct link. For this I used the Scripting.Dictionary object. In it, I matched the bad link with the good link.
RequestedBadLink = Request.ServerVariables("QUERY_STRING") '- Dictionary of known bad URL requests Set BadLinks = Server.CreateObject("Scripting.Dictionary") BadLinks.Add "404;http://example.com:80/bad-link","http://example.com/good-link" '- add more links here If BadLinks.Exists(RequestedBadLink) Then SuggestedURL = BadLinks.Item(RequestedBadLink) Else SuggestedURL = "" End If
For the bad links, I added “404;” to the front of the link and embedded “:80″ after the domain. This is the format that the QUERY_STRING ServerVariables uses. Then on your 404 page, you can test to see if you found a Suggested URL and display it for the user.



