【问题标题】:IIS7 Redirect using Rewrite module IssueIIS7重定向使用重写模块问题
【发布时间】:2015-05-26 03:22:23
【问题描述】:

我已更改域并尝试重定向除少数 URL 之外的所有请求。但是,我似乎无法让它按预期运行,并且所有内容都被重定向 - 我确信它一定很小 - 任何帮助将不胜感激!

我需要重定向所有 URL,除了路径为“auth”或“ipet”的任何内容,以及包含其查询字符串的 file.aspx。 olddomain.com 的其余部分都应该重定向到 newdomain.com。

<rule name="Redirect" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions trackAllCaptures="false" logicalGrouping="MatchAll">
    <add input="{HTTP_HOST}" pattern="www\.olddomain\.com" />
    <add input="{URL}" pattern="^file.aspx$" negate="true" />
    <add input="{URL}" pattern="^auth/?" negate="true" />
    <add input="{URL}" pattern="^ipet/?" negate="true" />
</conditions>
    <action type="Redirect" url="http://newdomain.com" />
</rule>

【问题讨论】:

    标签: regex redirect iis-7.5


    【解决方案1】:

    logicalGrouping="MatchAll" 表示所有条件都必须为真才能进行重定向。更改 logicalGrouping="MatchAny" 并更改匹配网址。

    <rule name="Redirect" enabled="true" stopProcessing="true">
    <match url="www\.olddomain\.com" />
    <conditions trackAllCaptures="false" logicalGrouping="MatchAny">
        <add input="{REQUEST_URI}" pattern=".*?file.aspx$" negate="true" />
        <add input="{REQUEST_URI}" pattern=".*?auth/?" negate="true" />
        <add input="{REQUEST_URI}" pattern=".*?ipet/?" negate="true" />
    </conditions>
        <action type="Redirect" url="http://newdomain.com" />
    </rule>
    

    【讨论】:

      【解决方案2】:

      使用以下.. 不带^

      <add input="{URL}" pattern=".*?auth/?" negate="true" />
      <add input="{URL}" pattern=".*?ipet/?" negate="true" />
      

      【讨论】:

      • 感谢 Karthik,尝试过,但它仍然重定向 - 正则表达式似乎通过了,但由于某种原因它仍然重定向。不确定我是否缺少另一个 IIS 重定向设置,或者它是否只是忽略了“否定”。
      • @Anton 您总是可以将它们拆分为两个单独的规则,明确指示在这种情况下取​​消重定向。
      • @ShellFish - 谢谢 - 这听起来像是一个主意..你能告诉我一个答案吗?我是 IIS 重定向的新手......
      猜你喜欢
      • 2012-03-25
      • 1970-01-01
      • 1970-01-01
      • 2010-10-06
      • 1970-01-01
      • 2016-10-06
      • 1970-01-01
      • 2011-01-26
      • 2010-11-06
      相关资源
      最近更新 更多