2012-03-21 61 views
1

我有一個功能完善的URL重寫來刪除文件擴展名。但是當我使用response.redirect時,URL重寫不會發生。奇怪的是,這隻有在URL使用完整路徑而不是相對時纔會發生。例如:使用URL重寫規則和SSL證書的跨域response.redirect

response.redirect("http://example.com/page") 

給我http://example.com/page.asp

response.redirect("/page")是罰款。

URL重寫代碼:

<rule name="rewrite asp"> 
    <match url="(.*)" /> 
    <conditions logicalGrouping="MatchAll"> 
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
    <add input="{REQUEST_FILENAME}" negate="true" pattern="(.*).asp" /> 
    </conditions> 
    <action type="Rewrite" url="{R:1}.asp" /> 
</rule> 

我需要使用的完整路徑,因爲我從一個域到另一個。有任何想法嗎?

+0

衛生署,對不起,這是Server.Transfer的 – 2012-03-21 20:34:03

+0

啊肯定,是的,我試過之一,沒有工作。 – greener 2012-03-21 20:38:06

+0

作爲最後一項建議,請嘗試添加查詢字符串,例如'response.redirect(「http://example.com/page/?test=1」)' – 2012-03-21 20:41:09

回答

0

你也許可以嘗試這樣的事情:

在redirect.asp的
/redirect?url=<%=Server.URLEncode("http://example.com/page.asp")%> 

則:

<%sSomeExternalURL = URLDecode(Request.QueryString("url"))%> 
<html> 
<head> 
    <meta http-equiv="refresh" content="0;url=<%=sSomeExternalURL%>"> 
</head> 
<body> 
</body> 
</html> 

<% 
Function URLDecode(str) 
    str = Replace(str, "+", " ") 
    For i = 1 To Len(str) 
     sT = Mid(str, i, 1) 
     If sT = "%" Then 
      If i+2 < Len(str) Then 
       sR = sR & _ 
        Chr(CLng("&H" & Mid(str, i+1, 2))) 
       i = i+2 
      End If 
     Else 
      sR = sR & sT 
     End If 
    Next 
    URLDecode = sR 
End Function 
%> 
+0

雖然問題在我的問題中沒有正確佈置,但您已經到達那裏了。謝謝。 – greener 2012-03-30 20:55:07

+0

你介意闡述嗎?我很高興能夠提供幫助,但我確信其他人可能想知道解決方案是什麼。 – 2012-03-30 22:55:39

+0

當然。我不認爲這會產生任何效果,但是被重定向到的域名具有SSL證書。所以還有一個其他的重寫規則。問題最終通過重定向到「https:// example.com/page」解決。 – greener 2012-03-31 16:33:04