IIS HTTP到HTTPS web.config重写不会返回整个URL [英] IIS HTTP to HTTPS web.config rewrite doesn't return entire URL

查看:325
本文介绍了IIS HTTP到HTTPS web.config重写不会返回整个URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So I have been trying to rewrite using the following:

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

在两种环境中,这会重定向。在第三种环境中,它不起作用。它不起作用,看着一个小提琴日志,我看到完整网址的http调用。当它重定向到https时,它会删除HTTP_HOST之后的所有内容。

In two environments, this redirects like it should. In a third environment, it doesn't work. It doesn't work in the sense of, looking at a fiddler log, I see the http call with the full url. When it redirects to https, it removes everything after the HTTP_HOST.

所以使用以下网址:


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

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

在两种环境中,它变为


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

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

第三个变为:


安全://www.mysite.com

secure://www.mysite.com

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

I tried rewriting it as https://{HTTP_HOST}{HTTP_URL} and that doubled the {URL} in the first two environments:


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

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

我对web.configs不是很有经验,我有点学习,如果有人对此处发生的事情有任何意见,我们将不胜感激。如果它与任何东西有任何关系,第三个环境在两个负载均衡的服务器上。

I'm not very experienced with web.configs, kinda learning as I go, so if anyone has any input as to what's going on here, it would be greatly appreciated. If it has any bearing on anything, the third environment is on two servers that are load balanced.

推荐答案

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

Ruslany has several IIS URL Rewrite examples on his blog, HTTP to HTTPS is one of them:

<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/ 了解更多信息。

这篇关于IIS HTTP到HTTPS web.config重写不会返回整个URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆