Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mortimer Henningsson 2 posts 72 karma points
    Nov 27, 2017 @ 15:31
    Mortimer Henningsson
    0

    Trouble with http to https and non-www to www redirects

    Hi,

    I'm using Umbraco 7.2 and am having some trouble with http to https and non-www to www redirects. We have several URLs matching different nodes in the Umbraco content tree using the hostnames and culture options like this:

    Top-level node 1 - matches sitename.se

    Top-level node 2 - matches sitename.com

    Top-level node 3 - matches othersite.se

    We want to setup redirect rules to force https and www-domains so that either of http://sitename.se, http://www.sitename.se or https://sitename.se becomes https://www.sitename.se for each domain respectively (ie. http://sitename.com becomes https://www.sitename.com). We'd like to do this dynamically as more domains might be used later on for localisation support.

    We're currently have the following 2 rules setup in UrlRewriting.config:

    <add name="forceWWW"
        virtualUrl="(https?)://(?!www\.)(.*)"
        redirectMode="Permanent"
        destinationUrl="$1://www.$2"
        ignoreCase="true"
        redirect="Domain"/>
    
    <add name="httpsRewrite"
      redirect="Domain"
      redirectMode="Permanent"
      virtualUrl="http://(.*)"
      destinationUrl="https://$1"
      ignoreCase="true"/>
    

    But unfortunately it's not working as intended. It seems to be working for one of the domains but only when using non-https so not quite sure what gives.

    Would very much appreciate any help on how to solve this or if there's any errors in the above rules.

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Dec 02, 2017 @ 12:09
    Alex Skrypnyk
    100

    Hi Mortimer

    Welcome to our forum!!!

    Maybe it makes sense to use rewrite rules?

    UrlRewriting is removed from latest Umbraco versions, we are using these rules for redirects to www, https or non-www:

    <rewrite>
      <rules>
        <!--<rule name="HTTP to HTTPS redirect" stopProcessing="true">
          <match url="(.*)"/>
          <conditions>
            <add input="{HTTP_HOST}" pattern="^domain.com$" negate="true"/>
            <add input="{HTTPS}" pattern="off" ignoreCase="true"/>
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent"/>
        </rule>-->
        <rule name="Redirect to non-www" stopProcessing="true">
          <match url="(.*)" negate="false"></match>
          <action type="Redirect" url="https://domain.com/{R:1}"></action>
          <conditions>
            <add input="{HTTP_HOST}" pattern="^domain.com$" negate="true"></add>
          </conditions>
        </rule>
    
          <!--<rule name="Redirect to www" stopProcessing="true">
            <match url="(.*)" />
            <conditions trackAllCaptures="false">
              <add input="{HTTP_HOST}" pattern="^domain.com$" />
            </conditions>
            <action type="Redirect"
              url="{MapProtocol:{HTTPS}}://www.domain.com/{R:1}" />
          </rule>-->
        </rules>
      <!--<rewriteMaps>
        <rewriteMap name="MapProtocol">
          <add key="on" value="https" />
          <add key="off" value="http" />
        </rewriteMap>
      </rewriteMaps>-->
    </rewrite>
    

    Thanks,

    Alex

  • Mortimer Henningsson 2 posts 72 karma points
    Dec 06, 2017 @ 08:41
    Mortimer Henningsson
    0

    Thanks for the help!

    Is there any way to do this without specifying the domain name? Tried modifying similar code myself to do this without any luck.

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Dec 06, 2017 @ 09:17
    Alex Skrypnyk
    0

    Hi Mortimer

    You can use {REQUEST_URI} token instead of the domain in rewrite rules, have a look at examples here:

    https://host4asp.net/top-iis-rewrite-rules/

    Thanks,

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft