【问题标题】:Http to Https URL rewritingHttp 到 Https URL 重写
【发布时间】:2017-08-29 10:30:28
【问题描述】:

我的要求很简单。我有Http://abc 需要使它成为Https://abc。我在 web.config 中添加了以下代码。即在 IIS 中添加新规则。 我已经关注了 IIS 中的 URL 重写模块。

<rewrite>
            <rules>
                <rule name="http to https" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^off$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" />
                </rule>
            </rules>
        </rewrite>

但它仍然对我不起作用。帮帮我。

【问题讨论】:

  • 你安装了IIS重写模块吗?
  • 是的。已经完成,从那里添加了新规则。该代码属于新规则本身。

标签: asp.net http https iis-8.5


【解决方案1】:

您使用的代码与我在生产中使用的代码非常相似,除了我使用redirectType="Permanent" 并且我碰巧使用硬编码域名来确保规范域并且我使用{R:1} 作为路径和查询但我认为使用{HTTP_HOST}{REQUEST_URI} 应该可以工作,但是您可能需要在两者之间使用斜线。

试试这个:

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

【讨论】:

  • 谢谢罗恩,但我也试过这个。它不工作。我以另一种方式得到它。我在 IIS 中创建了一个演示网站。提供相同的 DNS 名称(即来自 Http://abc 的 abc)。然后添加一个单独的 Html 页面,其中代码为 function redirecttoHttps() { var httpsUrl="https://abc"; window.location=httpsUrl; } redirecttoHttps(); 因此当用户键入 Http://abc 时,Html 页面内的脚本会将其推送到 Https://abc。不确定它是否推荐。因为最终在Https://abc 站点进行用户验证。我们所做的只是重定向。
  • 这很奇怪,您还可以尝试将url="https://{HTTP_HOST}/{R:1}" 更改为url="https://yourDomainHere.com/{R:1}",这实际上是我网站的配置方式。
猜你喜欢
  • 2016-03-20
  • 1970-01-01
  • 2014-07-18
  • 2019-04-11
  • 2014-09-20
  • 2011-06-02
  • 1970-01-01
  • 2012-07-23
  • 2016-06-30
相关资源
最近更新 更多