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.
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.
As far as I understand, you want to change the address value of a browser if the address contains "/home.asp" to "/". For example:
http://www.sitename.com/?some=querystring
instead of
http://www.sitename.com/home.asp?some=querystring
In classic asp, the script is working on the server before sending the result to the client, so there is no way to gather the browsers address value before executing the code, but with javascript etc. client-side scripting languages.
Using Request.ServerVariables with "URL", "PATH_INFO", "PATH_TRANSLATED" etc. just won't work because they are suppose to return the name of the "working-at-the-time" script (asp page).
But there is a way to redirect all your old home.asp pages to new root url. You can use a smiple querystring check against the new version of the site. For example:
If the old address was something like:
"http://www.sitename.com/home.asp?some=querystring&more=querystring"
Then redirect it to:
"http://www.sitename.com/?ver=2&" & Request.QueryString
In the script you can check if the querystring("v")=2 now to know for sure that the address is from new version else redirect it to /?v=2 no matter what was the url.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With