【问题标题】:IIS url rewrite role except some urlsIIS url 重写角色,除了一些 url
【发布时间】:2012-10-30 12:18:59
【问题描述】:

我在 URL 重写中得到了这条规则,它使用 HTTP 将对站点的每个请求重写为 HTTPS

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

我在这个角色中需要另一个规则或例外来重写或重定向特定的 URL 到 HTTP。

这可能吗?

【问题讨论】:

    标签: asp.net iis url-rewriting web-config


    【解决方案1】:

    您可以将不想执行重定向到 HTTPS 的异常添加为额外条件(不等于该 URL),如下所示:

    <rule name="Force HTTPS" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAll">
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
            <add input="{REQUEST_URI}" negate="true" pattern="^/noredirect/forthis/page\.aspx$" ignoreCase="true" />
            <add input="{REQUEST_URI}" negate="true" pattern="^/noredirect/forthis/page-as-well\.aspx$" ignoreCase="true" />
            <add input="{REQUEST_URI}" negate="true" pattern="^/noredirect/forthis/page-as-well-too\.aspx$" ignoreCase="true" />
        </conditions>
        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
    </rule>
    

    【讨论】:

    • 它会是这样的>> , ?谢谢回复
    • 只要 domain.com 是您网站根目录中的一个目录,那么可以。请注意,您应该在正则表达式中使用domain\.com 来逐字匹配 domain.com,否则点将使正则表达式接受那里的任何字符。如果您打算将 domain.com 作为域名进行匹配,则不能使用此选项,因为该域名未包含在 {REQUEST_URI} 变量中。
    • 我使用 IIS 向导从 URL 写入中排除特定域,结果创建了这样一行: 在条件节点中。虽然 SubStringOfURL 是我要排除的 URL 的子字符串。
    • 还可以尝试将 negate="true" 从标签中删除...这对我有用
    • 很高兴这是一件事。
    【解决方案2】:

    Web.config 中的例外规则,不将“NotSecurePage.ashx”重定向到 https:

    <system.webServer>
    <rewrite>
      <rules>
        <rule name="HTTP to HTTPS redirect" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
            <add input="{REQUEST_URI}" matchType="Pattern" pattern="\bNotSecurePage.ashx\b" ignoreCase="true" negate="true" /> <!-- Crystal não suporta imagens https.. Criando exceção para imagens de barcode, utilizadas no crystal -->
          </conditions>
          <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
        </rule>
      </rules>
    </rewrite>
    </system.webServer>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-03
      • 2016-06-27
      • 2013-06-16
      相关资源
      最近更新 更多