URL redirection on Classic Asp page

I have a redirect problem

I want to apply a redirect, if someone uses http://mywebsite.com/ then the URL will be redirected to http://www.mywebsite.com/ . I know that this is 302 redirection, but I don’t know how to use it when coding ........ what VBScript can be used for redirection?

My site is built in classic ASP and VBScript ... any piece of code would be better for me

thanks

+4
source share
2 answers

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

If this is not the case, simply enter Response.Redirect() into the appropriate URL, as it will do 302 for you:

eg.

 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 (ie 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 to ensure that the requested page and request is saved

+12
source

Try the following:

 Response.Status = "302 Moved Temporary" Response.AddHeader "Location", "http://www.mywebsite.com/" 
+4
source

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


All Articles