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
source share