?
Solved

Redirect to HTTPS results in Infinite LOOP

Posted on 2016-11-25
4
Medium Priority
?
213 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Four New Appliances. Same Industry-leading Speeds.

But don't take it from us.  The Firebox M370 is Miercom tested and Miercom approved, outperforming its competitors for stateless and stateful traffic throughput scenarios.  Learn more about the M370, M470, M570 and M670 and find the right solution for your organization today!

Question has a verified solution.

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

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

777 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