Request.ServerVariables("HTTP_HOST")
ホスト部分を取得して、それがで始まるかどうかを確認するために使用しますwww.
。
そうでない場合Response.Redirect()
は、302 を実行するため、適切な URL に a を発行するだけです。
例えば
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
上記は、要求されたページとクエリ文字列が保持されるようにリダイレクトを行います