【问题标题】:Cross-domain response.redirect with URL rewrite rules and SSL certificate带有 URL 重写规则和 SSL 证书的跨域 response.redirect
【发布时间】:2012-04-01 00:35:41
【问题描述】:

我有一个功能完善的 URL 重写来删除文件扩展名。但是当我使用response.redirect 时,不会发生 URL 重写。奇怪的是,这只发生在 URL 使用完整路径而不是相对路径时。例如:

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

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

response.redirect("/page") 很好。

网址重写代码:

<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>

我需要使用完整路径,因为我要从一个域转到另一个域。有什么想法吗?

【问题讨论】:

  • doh,对不起,这是 Server.Transfer
  • 啊,是的,是的,我试过了,但没有用。
  • 作为最后的建议,尝试添加一个查询字符串,例如'response.redirect("example.com/page/?test=1")'
  • 这给了我example.com/page.asp?test=1。我认为它必须在接收端,不会触发 URL 重写。
  • 我在这个关于重写规则的问题上看不到任何重写规则配置示例,这太奇怪了:/

标签: asp-classic url-rewriting cross-domain


【解决方案1】:

你可以试试这样的:

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

然后在redirect.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
%>

【讨论】:

  • 尽管我的问题没有正确说明问题,但您帮助实现了目标。谢谢。
  • 您介意详细说明吗?我很高兴能提供帮助,但我相信其他人可能想知道解决方案是什么。
  • 当然。我不认为这会产生任何影响,但是被重定向到的域具有 SSL 证书。所以还有一个其他的重写规则。问题最终通过重定向到https://example.com/page得到解决。
猜你喜欢
  • 2010-12-03
  • 1970-01-01
  • 1970-01-01
  • 2013-11-10
  • 1970-01-01
  • 1970-01-01
  • 2020-10-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多