2011-06-15 47 views
1

在我無法使用Web.Config的情況下,我正在爲舊URL執行301重定向,因此沒有重寫模塊功能。所以,我一直在使用單個文件這個簡單的代碼:301重定向包含變量的網址

<%@Language=VBScript %> 
<% 
Response.Status="301 Moved Permanently" 
Response.AddHeader ("Location","newurl.html") 
%> 

我的問題是,有一個網頁(的index.asp),其中變量是通過URL傳遞的是這樣的:

domain.com /index.asp?PageAction=VIEWPROD &的ProdID = 71 domain.com/index.asp?PageAction=VIEWPROD &的ProdID = 72

欲設置條件301重定向,這樣,當該URL的ProdID = 71它301到一個特定頁面,當URL是ProdID = 72時,它301到不同的頁面。

到目前爲止,我有這個簡單的代碼:

<% 
DIM strPageAction 
strPageAction = Request.QueryString("PageAction") 

DIM strProdID 
strProdID = Request.QueryString("ProdID") 
%> 

<% 
IF strPageAction = "VIEWPROD" AND strProdID = "71" THEN 
ELSE 
END IF 
%> 

<% 
IF strPageAction = "VIEWPROD" AND strProdID = "72" THEN 
ELSE 
END IF 
%>   

有誰知道我能得到一個301重定向存在的「然後」狀態?我很新,所以也許我錯過了一個簡單的解決方案...

「Response.Redirect」的作品,但給出了302而不是301.「Response.RedirectPermanent」的新選項不起作用在我的主機上。

回答

1

嗯,我發現一些代碼,做了工作:

<%@ Language=VBScript %> 
<% 
Response.Status="301 Moved Permanently" 

if Request.QueryString("PageAction") = "VIEWPROD" and Request.QueryString("ProdID") = "71" then 
Response.AddHeader "Location", "http://www.foxnews.com" 

else if Request.QueryString("PageAction") = "VIEWPROD" and Request.QueryString("ProdID") = "72" then 
Response.AddHeader "Location", "http://www.apple.com" 

end if 
end if 
%>