【问题标题】:HTTPS redirect on sub application子应用程序上的 HTTPS 重定向
【发布时间】:2016-05-18 08:57:18
【问题描述】:

我有一个使用此域 http://abc.example.com/portal 的应用程序。 Portal 是 IIS 上主应用程序 (abc.example.com) 的子应用程序。

如果有人通过http://abc.example.com/portal 访问它,我想重定向到https://abc.example.com/portal

我在 web.config 中添加了这些行:

<rewrite>
   <rules>
       <rule name="HTTPS Redirect" enabled="true">
           <match url="(.*)" ignoreCase="false" />
           <conditions>
               <add input="{HTTPS}" pattern="off" />
           </conditions>
           <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
       </rule>
    </rules>
</rewrite>

在此之后,如果我调用站点http://abc.example.com/portal,它会将我带到https://abc.example.com/,而不是https://abc.example.com/portal

你们知道我该怎么做吗?

谢谢,

【问题讨论】:

    标签: asp.net redirect iis


    【解决方案1】:

    尝试将您的规则更改为:

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

    另外,如果 /example 子目录是一个应用程序,请确保将这些重写规则放在该 web.config 中,而不是放在父应用程序的 web.config 中。

    【讨论】:

    • 我发现如果访问例如http://abc.example.com/portal/someFolder/SomePage.aspx?SomeQueryString,此规则会复制(并因此破坏)路径。对我有用的是&lt;action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" /&gt;
    猜你喜欢
    • 2014-07-17
    • 1970-01-01
    • 2021-08-21
    • 2023-03-28
    • 2013-08-27
    • 2018-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多