Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the *actual* client URL from a Classic ASP Request?

Tags:

asp-classic

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.

like image 873
Winston Fassett Avatar asked Mar 01 '23 15:03

Winston Fassett


2 Answers

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.

like image 179
D'Arcy Rittich Avatar answered Apr 02 '23 11:04

D'Arcy Rittich


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.

like image 23
htbasaran Avatar answered Apr 02 '23 11:04

htbasaran