【问题标题】:Conditoinal HTTP redirect IIS 7条件 HTTP 重定向 IIS 7
【发布时间】:2016-01-24 19:29:44
【问题描述】:

目前我正在将我的所有 http 请求重定向到 HTTPS,但现在我想添加条件,如果 URL 包含“admin”然后将 HTTP 请求重定向到 HTTPS,我如何更改规则来实现这一点(例如 http://www.example.com/admin/index.html) ?

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

【问题讨论】:

    标签: asp.net asp.net-mvc redirect iis iis-7.5


    【解决方案1】:

    将网址格式更改为:

    <match url=".*admin/.*" />
    

    这似乎与 IIS 模式匹配工具中的示例数据匹配。

    匹配其他部分,例如profile 你可以改变正则表达式:

    <match url=".*(admin|profile)/.*" />
    

    如果它总是以adminprofile 开头,那么您可以将正则表达式收紧为^(admin|profile)/.*^ 表示模式的开始,请参阅Defining a Pattern on this screen)。

    【讨论】:

    • 它的工作,另一个问题:我如何在这个规则中添加任何其他术语,例如如果在 URL 中找到“管理员”或“个人资料”,重定向将起作用?
    猜你喜欢
    • 2011-11-10
    • 2012-12-14
    • 2011-10-18
    • 2023-04-05
    • 2011-06-24
    • 2015-12-08
    • 2011-05-30
    • 2012-12-21
    • 2010-10-24
    相关资源
    最近更新 更多