Link to home
Start Free TrialLog in
Avatar of Michael Robinson
Michael RobinsonFlag for United States of America

asked on

Redirect to HTTPS results in Infinite LOOP

I'm trying to redirect all visitors in a sub directory to the HTTPS version, but when I use the code below, I get an endless loop.

I'm running IIS7.5 and I put this code into the web.config file in the root of my subdirectory.

What might be causing the infinite loop?

<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions><add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
Avatar of gdemaria
gdemaria
Flag of United States of America image

I don't know the correct syntax to fix it, but doesn't that rule apply to all URLs?   You want it only to apply to http:  and never https.
Here ya go

<rule name="Redirect to HTTPS" stopProcessing="true">
      <match url="(.*)" ignoreCase="true" />
      <conditions logicalGrouping="MatchAll">
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
Avatar of Michael Robinson

ASKER

dgrafx   - What does redirectType = "Found" do?  

Seems I should use redirectType="Permanent"      any thoughts?

The code below was found to work and not cause the infinite loop.  Not sure why it works while the code I initially showed causes the loop:

<rewrite>
            <rules>
                <rule name="HTTP to HTTPs" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent"/>
                </rule>
            </rules>
        </rewrite>
ASKER CERTIFIED SOLUTION
Avatar of dgrafx
dgrafx
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial