-3

我是一个剪切和粘贴非程序员。我什至不会拼写 ASP 或 HTML。所以我请我在微软的朋友为我编写以下代码,到目前为止它运行良好。但是现在我在 Microsoft 的朋友不再可用,我需要修改此代码以支持输入旧页面名称并将其重定向到新页面名称(如果需要,还可以使用目录)。我希望能够在代码中指定旧页面名称,并让代码给我一个 301 重定向到我在代码中指定的新页面名称。

任何人都可以为我编写修改并允许我将其剪切并粘贴到我的包含文件中吗?这是现有包含文件的代码...

<%
Dim serverName 
serverName = Request.ServerVariables("SERVER_NAME")

Dim redirectUrl
redirectUrl = "/domains4sale.asp"

Dim canRedirect 
canRedirect = "False"

Dim hostNameArray(14) 'Array of host name

hostNameArray(0) = "bananapages.net"
hostNameArray(1) = "www.bananapages.net"
hostNameArray(2) = "6379100.com"
hostNameArray(3) = "www.6379100.com"
hostNameArray(4) = "caribbeanexhibits.com"
hostNameArray(5) = "www.caribbeanexhibits.com"
hostNameArray(6) = "caribbeanspecialevents.com"
hostNameArray(7) = "www.caribbeanspecialevents.com"
hostNameArray(8) = "caribeexpo.com"
hostNameArray(9) = "www.caribeexpo.com"
hostNameArray(10) = "daleallenenterprises.com"
hostNameArray(11) = "www.daleallenenterprises.com"
hostNameArray(12) = "rrcpapsc.com"
hostNameArray(13) = "www.rrcpapsc.com"
hostNameArray(14) = "daleallen.com"


If serverName = "www.daleallen.com" Then
     redirectUrl = Request.ServerVariables("HTTP_X_REWRITE_URL")
     If Cint(InStr(redirectUrl, "/2010-website/")) >= 1 Then
        canRedirect = "True"
        redirectUrl = Replace(redirectUrl, "/2010-website/", "/")
    End If 
Else
    For Each item In hostNameArray
     If serverName = item  Then
        serverName = "www.daleallen.com"
        canRedirect = "True"
        If(item = "daleallen.com") Then
            redirectUrl = Request.ServerVariables("HTTP_X_REWRITE_URL") 
            redirectUrl = Replace(redirectUrl, "/2010-website/", "/")
        End If      
        Exit For
     End If
    Next

End If

If canRedirect = "True" Then
    Response.Status="301 Moved Permanently"
    If Request.QueryString <> "" Then
      Response.AddHeader "Location", "http://" & serverName & redirectUrl & "?"     &           Request.QueryString  
    Else
        Response.AddHeader "Location", "http://" & serverName & redirectUrl 
    End If 
End If 
%>  
4

1 回答 1

0

从原始代码中的这些行开始

If Cint(InStr(redirectUrl, "/2010-website/")) >= 1 Then
    canRedirect = "True"
    redirectUrl = Replace(redirectUrl, "/2010-website/", "/")
End If 

你需要在它之后立即添加类似的东西 - 例如

If Cint(InStr(redirectUrl, "yourolddirectory/youroldfilename.html")) >= 1 Then
    canRedirect = "True"
    redirectUrl = Replace(redirectUrl, "yourolddirectory/youroldfilename.html", "yournewdirectory/yournewfilename.html")
End If 
于 2013-09-17T11:45:20.540 回答