【问题标题】:HTTPS Redirect not working quite rightHTTPS 重定向无法正常工作
【发布时间】:2017-03-04 17:10:28
【问题描述】:

我在我的 ASP.NET web.config 文件中使用以下代码将“www”请求重定向到我的安全网站:

<rewrite>
    <rules>
      <clear/>
      <rule name="httpsredirect" stopProcessing="true">
        <match url="(.*)" />
        <conditions>
          <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        </conditions>
        <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{REQUEST_URI}" />
      </rule>
    </rules>
</rewrite>

目标是确保当有人进入时

http://www.example.com/somepage.aspx

他们被重定向到

https://www.example.com/somepage.aspx

问题是重定向在将它们发送到安全站点时工作得很好,但是缺少目标 URI,因此它们被发送到站点的根默认页面。这里有什么帮助吗?谢谢! 现在

【问题讨论】:

    标签: asp.net https web-config url-redirection


    【解决方案1】:

    尝试改变

    <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{REQUEST_URI}" />
    

    <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
    

    【讨论】:

    • 奇怪的是,它做到了。我早些时候尝试过,但没有运气。也许我的字符串中有一些内容(我只是复制并粘贴了你的!)。非常感谢!
    【解决方案2】:

    如果您查看答案here,您会发现他们拥有url="https://{HTTP_HOST}{REQUEST_URI}",而不是您的url="https://{HTTP_HOST}/{REQUEST_URI}"

    【讨论】:

      猜你喜欢
      • 2020-01-16
      • 2015-08-12
      • 2021-04-11
      • 2015-07-02
      • 2017-09-23
      • 2015-08-09
      • 2014-07-01
      • 2015-12-21
      相关资源
      最近更新 更多