views:

834

answers:

4

Trying to do some SEO healing on an old (Classic) ASP site.

The main page has long been home.asp but we want all inbound links to go to the site root ("/") instead. Made the changes to the pages but now we need to do a redirect so we don't have broken legacy inbound links.

I basically want to do this:

<% if Request.ServerVariables("PATH_INFO") = "/home.asp" then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.mysite.com/"
end if %>

The problem is, that the PATH_INFO, SCRIPT_NAME, and PATH_TRANSLATED variables all return "/home.asp" even when I go to the site root. So it ends up in a never ending loop redirecting to itself.

Any ideas?

Edit

To clarify, I know that the default doc in IIS is set to home.asp and had already thought of the workaround suggested. However, I don't currently have the privileges to change it, which is why I'm asking here if there is any way to ask ASP what the URL the client used. It appears there is no way to do this, so I will petition for access to change the welcome page to something else.

A: 

The reason they are going back to home.asp is because the default content document in the IIS configuration for the site will have home.asp listed above the other pages you have, and possibly the one you want.

Although HTTP allows you to request a directory... ie http://www.example.com/ almost all servers serve one of the pages in the site for this document, it is often called default.* or index.* (where * is any content type extension processed by the server.)

Removing home.asp from the Documents tab will prevent the infinite loop, but you may find you have inadvertantly broken your website as well.

David McEwing
+2  A: 

I would create a new default document to serve up the home page, e.g., index.asp, and make sure index.asp is setup as the topmost default document in IIS.

RedFilter
+1  A: 

You could create a session object when the page is first redirected and then check for that session before redirecting again (it's been a few years since I've worked in classic asp, but this should work):

<% 
if Request.ServerVariables("PATH_INFO") = "/home.asp" AND NOT Session("HasBeenHere") then
  Session("HasBeenHere") = True
  Response.Status="301 Moved Permanently"
  Response.AddHeader "Location","http://www.mysite.com/"
end if 
%>
Metro Smurf
+1, but you should really get the value of Session before the IF and compare it as a string as otherwise the first time you run this it'll crash because you're trying to cast a null to a boolean
RobV
In classic ASP/VBScript, the Session will evaluate to False if it has not been set. Maybe in VB6 you have to cast it first?
Metro Smurf
A: 

One thing to check is if there are any documents in the default list that are higher than home.asp. If you don't have administrative access, you could experiment by creating pages like this:

index.asp
default.asp

etc etc. If you can find a filename that has a higher priority than home.asp, you can then duplicate the contents in home.asp into this new file, and change home.asp to just redirect to the root.

If home.asp is the highest entry in the list, then the only thing I can suggest is outputting a complete list of the HTTP headers and comparing the output generated when you visit / as opposed to visiting /home.asp. Hopefully you'll spot a difference you'll be able to exploit.

<%
  for each header in Request.ServerVariables
      response.write header & " : " & Request.ServerVariables(header) & "<br />"
  next
%>
Jamie