iisurl-rewritingwindows-server-2012-r2iis-8.5

IIS Rewrite Global Rule working on Default Document Only


Migrating servers and experiencing an issue with URL Rewrite in IIS. The rule works perfectly on our prior servers, but the rule only functions correctly on the default document at the base domain address. The rule is configured as a global rule within IIS.

Rule works at: domain.com/

Rule fails at: domain.com/any-address-here

Rule details: We are matching everything, taking the incoming IP address and passing it to our header. This was configured within IIS and verified within the (/Windows/System32/insetsrv/config/applicationHost.config) file. Server software: Windows 2012R2. Using IIS 8.5.9600.16384 and Microsoft URL Rewrite Module 2.

<match url="(.*)" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
    <add input="{HTTP_X_Forwarded_For}" pattern="^([0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3})(.)*$" />
</conditions>
<serverVariables>
    <set name="REMOTE_ADDR" value="{C:1}" />
</serverVariables>
<action type="Rewrite" url="{R:0}" />

Solution

  • Simple workaround, not a fix. Global rules were simply not being fully recognized in IIS, so the rules were re-configured as Distributed rules. IIS then recognized the rules, but we were receiving 500 error messages. We needed to add Server Variables to complete the rewrites successfully.

    Side-note. We had installed URL Rewrite as a standalone application from the Microsoft website but after reading about how this could be problematic - we re-installed the URL Rewrite application via the Web Platform Manager as recommended. This had no effect on the Global Rule vs Default Document rewrite issue above.