• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 360
  • Last Modified:

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$" />
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
  • 2
1 Solution
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" />
      <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
bigmikey88Author Commented:
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:

                <rule name="HTTP to HTTPs" stopProcessing="true">
                    <match url="(.*)" />
                        <add input="{HTTPS}" pattern="off" />
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent"/>
Your issue I believe was "^OFF$" instead of "off"

redirectType – Specifies the status code to use during redirect:
301 – Permanent
302 – Found
303 – See other
307 – Temporary

A 301 redirect means that the page has permanently moved to a new location. A 302 redirect means that the move is only temporary. Search engines need to figure out whether to keep the old page, or replace it with the one found at the new location.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now