Windows – IIS7 URL Rewrite – Checking for X-Forwarded-For header

httpiisrewritewindowswindows-server-2008-r2

I am pretty familiar with IIS and URL Rewrite but I just got a task which stumped me. I need to check each request for the presence of the X-Forwarded-For HTTP header and, depending on its presence, redirect the request.

How can I check for this header?

Best Answer

Try something like the following:

<rewrite>
  <rules>
    <rule name="RedirectBasedOnForwardedFor" patternSyntax="Wildcard" stopProcessing="true">
      <match url="*" />
      <conditions>
        <add input="{HTTP_X_Forwarded_For}" pattern="insert your pattern here" />
      </condiations>
      <action type="Redirect" url="/newurl/" />
    </rule>
  </rules>
</rewrite>