I have the following rewrite rule that works perfectly fine on a regular asp.net project, running on IIS7.
<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>
So one of our pages when visited at http://{domain}/aboutus
will redirect to https://{domain}/aboutus
. Now putting the same rewrite rule in an Umbraco site causes an infinite loop. We don't have any other rewrite rule for our Umbraco site. That leads me to think that Umbraco is somewhat hijacking the routing from http to https and causes the infinite loop. What are we missing?
I recommend using the following rule instead:
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}"
redirectType="Permanent" appendQueryString="false" />
</rule>
As your regex for url isn't filters the input (<match url="(.*)" />
), you should use redirectType="Permanent"
parameter in your code:
More information can be found here:
Add an Url Rewrite rule
One thing worth noting is that by default the re-directs are 302 re-directs, if you want to do 301 re-directs you need to add the following:
redirectMode="Permanent"
You can find the full instructions for the URL re-writing component on their website: https://github.com/aspnetde/UrlRewritingNet
One potential solution is to use the Umbraco rewrite module rather than an IIS rewrite.
In the URL rewriting config file (Config/UrlRewriting.config
), the following rule is a simple example of how to redirect from HTTP to HTTPS:
<add name="https Rewrite"
redirect="Domain"
redirectMode="Permanent"
virtualUrl="http://(.*)"
destinationUrl="https://$1"
ignoreCase="true" />
This rule should be placed within the <rewrites>
section.
Edit: As per sebastiaan's comment, the urlRewriting.net module is outdated and an IIS solution should be used where possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With