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?


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


我建议使用以下规则:

<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>

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.

链接地址: http://www.djcxy.com/p/82996.html

上一篇: 推荐的方式来获得砂浆屏幕内的活动?

下一篇: Umbraco https重写规则会导致无限循环