Question

I would like to redirect all traffice coming from http://www.example.com to http://www.mysite.com/badreferer.aspx?bad=true

for this i tried to create a rule in web.config file of http://www.mysite.com in IIS7.

<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>

But having issue with redirect loop.

Please help.

Thanks.

Was it helpful?

Solution

Try this:

<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>

update:

<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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top