Reputation: 61
To redirect my visitors to https I used this rule in my web.config:
<rewrite>
<rules>
<clear />
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
But I get errors (too many redirects) when I try to visit the website, it seems it gets stuck in a loop.
https://example.com and https://www.example.com are ok.
But these addresses result in an error:
example.com & www.example.com
Can anyone help me with this?
Upvotes: 0
Views: 6739
Reputation: 61
I found a solution in these rules:
<rules>
<clear />
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com$" negate="true" />
<add input="{HTTPS}" pattern="OFF" ignoreCase="true" />
</conditions>
<action type="Redirect" url="http://example.com/{R:1}" />
</rule>
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^example\.com$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
Upvotes: 0
Reputation: 11
If You have an endless loop of redirecting. Try this tips.
"login.php" redirects to "login.php" if you're not logged in. "login.php" redirects to "login.php" if you're not logged in. "login.php" redirects to "login.php" if you're not logged in. "login.php" redirects to "login.php" if you're not logged in. etc.
You should probably make the redirect happen only when the current page is not "login.php"; i.e. remove that logic from this page.
Upvotes: 1