Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Url Redirection in Classic Asp page

I have a issue related to redirection

I want to apply redirection if someone uses http://mywebsite.com/ then the URL would be redirected to http://www.mywebsite.com/. I know it is a 302 redirection but I dont know how to apply it in coding ........ what VBScript could be used for applying redirection ??

My website is build in Classic ASP and VBScript ... any piece of code would be better for me

Thanks

like image 858
NewbieFreak Avatar asked Dec 03 '22 09:12

NewbieFreak


2 Answers

Use Request.ServerVariables("HTTP_HOST") to get the host part so that you can check if it starts with www. or not.

If it doesn't then just issue a Response.Redirect() to the appropriate URL since it'll do a 302 for you:

e.g.

If Left(Request.ServerVariables("HTTP_HOST"), 4) <> "www." Then
  Dim newUri
  'Build the redirect URI by prepending http://www. to the actual HTTP_HOST
  'and adding in the URL (i.e. the page the user requested)
  newUri = "http://www." & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("URL")

  'If there were any Querystring arguments pass them through as well
  If Request.ServerVariables("QUERY_STRING") <> "" Then
    newUri = newUri & "?" & Request.ServerVariables("QUERY_STRING")
  End If

  'Finally make the redirect
  Response.Redirect(newUri)
End If

The above does a redirect ensuring the requested page and querystring are preserved

like image 89
RobV Avatar answered Mar 16 '23 05:03

RobV


Try this:

Response.Status = "302 Moved Temporary"
Response.AddHeader "Location", "http://www.mywebsite.com/" 
like image 31
Randam Avatar answered Mar 16 '23 03:03

Randam