Solved

Redirect to HTTPS results in Infinite LOOP

Posted on 2016-11-25
4
86 Views
Last Modified: 2016-12-03
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>
0
Comment
Question by:bigmikey88
  • 2
4 Comments
 
LVL 39

Expert Comment

by:gdemaria
ID: 41902550
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.
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 41902562
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>
0
 

Author Comment

by:bigmikey88
ID: 41902673
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>
0
 
LVL 25

Accepted Solution

by:
dgrafx earned 500 total points
ID: 41902740
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.

https://www.hochmanconsultants.com/301-vs-302-redirect/
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
Microservice architecture adoption brings many advantages, but can add intricacy. Selecting the right orchestration tool is most important for business specific needs.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now