Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Umbraco https rewrite rule causes an infinite loop

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?

like image 261
von v. Avatar asked Dec 23 '14 00:12

von v.


3 Answers

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>
like image 93
sebastiaan Avatar answered Sep 20 '22 00:09

sebastiaan


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

like image 21
VMAtm Avatar answered Sep 19 '22 00:09

VMAtm


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.

like image 22
LoveFortyDown Avatar answered Sep 20 '22 00:09

LoveFortyDown