我有一个与重定向相关的问题
我想申请重定向,如果有人使用http://mywebsite.com/,那么网址将被重定向到http://www.mywebsite.com/。我知道这是一个302重定向,但我不知道如何在编码中应用它......什么VBScript可以用来申请重定向??
我的网站是建立在经典的ASP和VBScript…任何一段代码对我来说都更好
谢谢
发布于 2011-02-01 20:59:31
使用Request.ServerVariables("HTTP_HOST")获取主机部分,以便检查它是否以www.开头。
如果没有,那么只需向相应的URL发出一个Response.Redirect(),因为它将为您执行一个302:
例如:
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-01 20:58:57
试试这个:
Response.Status = "302 Moved Temporary"
Response.AddHeader "Location", "http://www.mywebsite.com/" https://stackoverflow.com/questions/4859316
复制相似问题