4

リダイレクトに関連する問題があります

誰かが使用した場合にリダイレクトを適用したい場合http://mywebsite.com/、URL は にリダイレクトされhttp://www.mywebsite.com/ます。302リダイレクトであることは知っていますが、コーディングに適用する方法がわかりません........リダイレクトを適用するためにどのVBScriptを使用できますか??

私の Web サイトは Classic ASP と VBScript で構築されています。

ありがとう

4

2 に答える 2

12

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

上記は、要求されたページとクエリ文字列が保持されるようにリダイレクトを行います

于 2011-02-01T12:59:30.610 に答える
5

これを試して:

Response.Status = "302 Moved Temporary"
Response.AddHeader "Location", "http://www.mywebsite.com/" 
于 2011-02-01T12:58:56.880 に答える