Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Thursday, July 14, 2016

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

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


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.

Answer by David McEwing for How to get the *actual* client URL from a Classic ASP Request?


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.

Answer by RedFilter for How to get the *actual* client URL from a Classic ASP Request?


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.

Answer by Metro Smurf for How to get the *actual* client URL from a Classic ASP Request?


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   %>  

Answer by Jamie for How to get the *actual* client URL from a Classic ASP Request?


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) & "
" next %>

Answer by RobV for How to get the *actual* client URL from a Classic ASP Request?


Does Request.ServerVariables("URL") not give you the correct value?

As far as I am aware that should be the URL from the actual HTTP Request the user made

Answer by htbasaran for How to get the *actual* client URL from a Classic ASP Request?


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.


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.