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

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

问题描述

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

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?

我在 IIS 上禁用了 Require SSL.

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>

谢谢.

推荐答案

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

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>

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

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 上从 http 到 https 的 URL 重写不起作用,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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