IIS 上的 URL 重写从 http 到 https 不起作用, [英] URL Rewrite on IIS from http to https is not working,

查看:34
本文介绍了IIS 上的 URL 重写从 http 到 https 不起作用,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题.在 IIS 上,我得到了一个带有两个端口 80443(https) 的网站.我想将所有 http 请求从用户重定向到 https.我还添加了 Rewrite rule to https,但是当我在浏览器中输入 http://localhost/site 时,它给了我相同的页面.我需要将用户重定向到 httpS://localhost/site.

也许这是因为我的本地配置?

我在 IIS 上禁用了 Require SSL.

规则是:<重写><规则><规则名称="HTTPS 重定向"><match url="(.*)" ignoreCase="false"/><条件><add input="{HTTPS}" pattern="off" ignoreCase="false"/></条件><action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}"/></规则></规则></rewrite>

谢谢.

解决方案

以下是我们在生产 IIS 7 站点上使用的将所有请求从 HTTP 重定向到 HTTPS 的确切规则

<预><代码><配置><system.webServer><重写><规则><规则名称="重定向到 HTTPS" stopProcessing="true"><match url="(.*)"/><条件><add input="{HTTPS}" pattern="^OFF$"/></条件><action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found"/></规则></规则></rewrite></system.webServer></配置>

您发布的内容与我们使用的内容之间存在一些细微差别.此外,由于您在本地主机上运行,​​因此您不会使用带有 Visual Studio 的内置 Web 服务器吗?我认为它不会处理 IIS 重写规则.

I have a problem. On IIS I got a web-site with two ports 80 and 443(https). I want to redirect all the http requests from user to https. I also added Rewrite rule to https, but when I enter in browser http://localhost/site it gives me the same page. I need to redirect user to httpS://localhost/site.

Maybe this is because of my local configurations?

And I disable Require SSL on IIS.

The rule is:
<rewrite>
  <rules>
    <rule name="HTTPS Redirect">
      <match url="(.*)" ignoreCase="false" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="false" />
      </conditions>
      <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" />
    </rule>
  </rules>
</rewrite>

Thank you.

解决方案

Below is the exact rule we use on a production IIS 7 site to redirect all request from HTTP to HTTPS

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <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="Found" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

There are some minor differences between what you have posted and what we use. Also, since you are running on local host, you wouldn't be using the built-in web server with visual studio would you? I don't think it will process IIS rewrite rules.

这篇关于IIS 上的 URL 重写从 http 到 https 不起作用,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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