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
Solved

Redirect to HTTPS results in Infinite LOOP

Posted on 2016-11-25
4
134 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

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

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

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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