url rewrite - error此网页有一个重定向循环

时间:2013-05-29 16:37:03

标签: iis-7 url-rewriting http-referer url-redirection

我想将所有来自http://www.example.com的广告转移到http://www.mysite.com/badreferer.aspx?bad=true

为此我尝试在IIS7中的http://www.mysite.com的web.config文件中创建规则。

<rule name="bad referer" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
                    <add input="{HTTP_REFERER}" pattern="(.*)example(.*)" />
      </conditions>
      <action type="Redirect" url="/badreferer.aspx?bad=true" appendQueryString="false" />          
    </rule>

但是遇到了重定向循环的问题。

请帮忙。

感谢。

1 个答案:

答案 0 :(得分:1)

试试这个:

<rules>
  <rule name="bad referer" stopProcessing="true">
    <match url="^(.*)" />
    <conditions>
      <add input="{HTTP_REFERER}" pattern="http://www.example.com(.*)" negate="true" />
    </conditions>
    <action type="Redirect" url="http://www.website.com/badreferer.aspx?bad=true" />
  </rule>
</rules>

更新

<rule name="bad referer" stopProcessing="true">
    <match url=".*" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
        <add input="{REQUEST_URI}" pattern="/badreferer\.aspx?bad=true" negate="true" />
        <add input="{HTTP_REFERER}" pattern="^www.\example\.com.*" />
    </conditions>
    <action type="Redirect" url="/badreferer.aspx?bad=true" appendQueryString="false" />
</rule>