How to get * actual * client url from 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 incoming links to go to the root site ("/"). Made changes on the pages, but now we need to redirect so that we do not have broken external 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 return "/home.asp" even when I go to the root of the site. Thus, it ends with an endless cycle redirecting to itself.

Any ideas?

Edit

To clarify, I know that the default document in IIS is set to home.asp and was already thinking of a workaround. However, I don’t have the right to change it at this time, so I am asking here if there is a way to ask the ASP that the client is URL, There seems to be no way to do this, so I will request access to change the welcome page to something else.

+4
source share
6 answers

I would create a new default document to serve the home page, such as index.asp, and make sure index.asp is configured as the top-most default document in IIS.

+2
source

As I understand it, you want to change the value of the browser address if the address contains "/home.asp" to "/". For instance:

 http://www.sitename.com/?some=querystring 

instead

 http://www.sitename.com/home.asp?some=querystring 

In the classic asp script, it runs on the server before sending the result to the client, so there is no way to collect the value of the browser address before executing the code, but with javascript, etc. in client scripting languages,

Using Request.ServerVariables with parameters "URL", "PATH_INFO", "PATH_TRANSLATED", etc. it just won’t work, because they must return the name of the “running for a while” script (asp page).

But there is a way to redirect all your old home.asp pages to the new root URL. You can use the invitation request check for the new version of the site. For instance:

If the old address was something like this:

 "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 querystring ("v") = 2 really knows that the address from the new else version redirects it to /? v = 2 no matter what the URL was.

+2
source

The reason they return to home.asp is because the default configuration document for the IIS configuration for the site will contain home.asp, listed above your other pages and possibly the one you want.

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

Removing home.asp from the Documents tab will prevent an endless loop, but you may find that you also accidentally broke your site.

+1
source

You can create a session object when the page is first redirected, and then check this session before re-redirecting (several years have passed since I 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 %> 
+1
source

Check if there are any documents in the default list that are higher than home.asp. If you do not have administrative access, you can experiment by creating these pages:

 index.asp default.asp 

etc. If you can find a file name with a higher priority than home.asp, you can then duplicate the contents in home.asp to this new file and change home.asp to just redirect it to the root directory.

If home.asp is the highest entry in the list, then the only thing I can offer is to output a complete list of HTTP headers and compare the output generated by visiting / as opposed to visiting /home.asp. I hope you notice the difference that you can use.

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

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

To my knowledge, this should be the URL of the actual HTTP request made by the user.

+1
source

Source: https://habr.com/ru/post/1285983/


All Articles