Link to home
Start Free TrialLog in
Avatar of Ted Pezzullo
Ted PezzulloFlag for United States of America

asked on

IIS 7.5 - redirect old URL to new URL causing too many redirects error

We are trying to implement a redirect rule in our web.config file that can redirect incoming traffic using our old URL to point to the new URL.  The code we are trying to use is causing a too many redirects error:

There were too many redirections.
Error Code: INET_E_REDIRECT_FAILED

Our current rewrite rules only have an HTTP to HTTPS redirect:
      <rules>
        <rule name="HTTP to HTTPS redirect" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
        </rule>

      </rules>

Open in new window


However, when I update the rules to the following, we get the error.
      <rules>

       <rule name="oldsite.org to newsite.org" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" negate="true" pattern="^oldsite\.org$" />
          </conditions>
          <action type="Redirect" url="https://www.newsite.org/{R:1}" redirectType="Permanent" />
        </rule>

        <rule name="HTTP to HTTPS redirect" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
        </rule>

      </rules>

Open in new window


I have tried various tweaks to the code (including disabling the HTTPS rule, changing {R:1} to R:0}, and stopProcessing="false"), with no success.

Once this is corrected, I have a followup question - do I need to enter a new rule for each old domain that we want to redirect (we have several that older members (and staff) continue to use out of habit), or can we add another condition/<add ... pattern="^anotheroldsite\.org$"> line?

Thanks in advance!
Avatar of arnold
arnold
Flag of United States of America image

why not have both in place, add a transition page instead that checks the requested URL notifies the user that this site is going away in by next year, update your favorites, shortcuts and redirect.

Your match url should be a variation of *.oldsite.org
your negation condition starts with oldsite.org as the request not sure that will ever match.
Negate to make sure the request is not for a newsite.
The negate condition isn't right, by having that in there you're basically saying anything that comes in that does NOT match oldsite.org, redirect it to www.newsite.org.

So the redirect will happen, fail again because "www.newsite.org" does NOT match oldsite.org, and redirect again.  And again and again.

You can join both the ssl check and the domain into one rule, using the "MatchAny" logical grouping.
If new domain is the only one you're going to have, the easiest way is to redirect ANY domain other than the full "www.newsite.org".

      <rules>
        <rule name="any other domain, non-www or non-ssl" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAny">
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
            <add input="{HTTP_HOST}" pattern="^www\.newsite\.org$" ignoreCase="true" negate="true" />
          </conditions>
          <action type="Redirect" url="https://www.newsite.org/{R:1}" redirectType="Permanent" />
        </rule>
      </rules>

Open in new window

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.