【问题标题】:IIS HTTP to HTTPS web.config rewrite doesn't return entire URLIIS HTTP 到 HTTPS web.config 重写不返回整个 URL
【发布时间】:2013-02-02 05:59:54
【问题描述】:

所以我一直在尝试使用以下内容重写:

<rules>
  <rule name="HttpToHttps" stopProcessing="true"/>
    <match url="(.*)"/>
    <conditions>
      <add input="{HTTPS}" pattern="off" ignoreCase="true"/>
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}{URL}"/>
  </rule>
<rules>

在两种环境中,这会像它应该的那样重定向。在第三种环境中,它不起作用。从某种意义上说,它不起作用,查看提琴手日志,我看到带有完整 url 的 http 调用。当它重定向到 https 时,它会删除 HTTP_HOST 之后的所有内容。

所以使用以下网址:

nonsecure://www.mysite.com/page.aspx?var1=1&var2=2

在两种环境下,变成了

secure://www.mysite.com/page.aspx?var1=1&var2=2

第三个变成:

安全://www.mysite.com

我尝试将其重写为 https://{HTTP_HOST}{HTTP_URL} 并且在前两个环境中将 {URL} 翻倍:

secure://www.mysite.com/page.aspx?var1=1&var2=2&var1=1&var2=2

我对 web.configs 不是很有经验,我边走边学,所以如果有人对这里发生的事情有任何意见,我将不胜感激。如果它对任何事情有任何影响,则第三个环境位于两台负载平衡的服务器上。

【问题讨论】:

  • nonsecure = http 和 secure = https - 它在向我大喊要发布两个以上的链接。

标签: iis url-rewriting web-config


【解决方案1】:

Ruslany 在他的博客上有几个 IIS URL Rewrite 示例,HTTP to HTTPS 就是其中之一:

<rule name="Redirect to HTTPS" stopProcessing="true">
  <match url="(.*)" />
  <conditions>
    <add input="{HTTPS}" pattern="^OFF$" />
  </conditions>
  <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>

请参阅http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/ 了解更多信息。

【讨论】:

  • 这是一些有用的信息 - 但是它仍然不起作用。
  • @Nick Strange,那么可能还有其他因素在起作用。上面的规则在我的场景中完美运行:GET http://ssl.example.com/?var1=1&amp;var2=2&amp;var3=aaa&amp;var4=lkesr HTTP/1.1 User-Agent: Fiddler Host: ssl.example.com HTTP/1.1 301 Moved Permanently Content-Type: text/html; charset=UTF-8 Location: https://ssl.example.com/?var1=1&amp;var2=2&amp;var3=aaa&amp;var4=lkesr Server: Microsoft-IIS/8.0(我不得不修改我的测试域)
  • 我会对此表示赞同,但是我需要 15 声望才能这样做:/。问题是负载均衡器上也有一个 url 重写规则,它正在咀嚼 url 的查询部分,然后返回基本部分。
猜你喜欢
  • 2016-03-20
  • 1970-01-01
  • 2017-08-23
  • 2012-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-23
  • 1970-01-01
相关资源
最近更新 更多