Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1284 posts 2741 karma points
    Jul 13, 2015 @ 13:55
    Amir Khan
    0

    Redirect to https

    Hi,

    I'm trying to create a simple rewrite rule to force https and add www on a certain domain.

    Any idea why this doesn't work? Seems to just be ignored.

    Thank you,

    Amir

    <add name="domainRewriteHttps"
                virtualUrl="https://domain.com/“
                rewriteUrlParameter="ExcludeFromClientQueryString"
                destinationUrl="https://www.domain.com/"
                redirect="Domain"
                redirectMode="Permanent"
                ignoreCase="true" />
    
  • Dan Lister 416 posts 1974 karma points c-trib
    Jul 13, 2015 @ 14:01
    Dan Lister
    0

    Hi Amir,

    As an alternative solution, I use the following rule to force HTTPS requests on a web site. This can be added to web.config. You'll need IIS Url Rewrite installed on your web server for this to work. The rule below uses the current request's host so it will work for any site.

    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <rule name="Redirect to HTTPS" enabled="false">
              <match url="(.*)" />
              <conditions>
                <add input="{HTTPS}" pattern="off" />
              </conditions>
              <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>
    

    If you wanted it to work for a certain domain only, you could replace the {HTTP_HOST} reference with a specific domain.

    I hope that helps.

    Thanks, Dan.

  • Amir Khan 1284 posts 2741 karma points
    Jul 13, 2015 @ 14:09
    Amir Khan
    0

    Hi Dan, I'd like to do this for just one domain on the site though...Any advantage to doing this in web.config vs urlrewriting.config?

  • Michael Harper 23 posts 134 karma points
    May 25, 2018 @ 19:39
    Michael Harper
    0

    This was helpful - thanks!

  • Dan Lister 416 posts 1974 karma points c-trib
    Jul 13, 2015 @ 14:14
    Dan Lister
    0

    Hi Amir,

    You could just amend the rule to the following line if you just wanted to for secure connections for just one domain:

    <action type="Redirect" url="https://www.domain.com/{R:1}" redirectType="Permanent" />
    

    I prefer using a web.config rule as the redirect is performed by IIS, not the application. I assume this would speed things up slightly and also allow the application not to have to worry about whether a connection is secure or not.

    Thanks, Dan.

  • Claushingebjerg 939 posts 2574 karma points
    Mar 29, 2017 @ 08:38
    Claushingebjerg
    0

    I have an umbraco instrance containing two sites with a domain mapping each. I need one of them to run https, but cant get the above redirect to work...

      <rewrite>
      <rules>
        <rule name="Redirect to HTTPS" enabled="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="off" />
          </conditions>
          <action type="Redirect" url="https://www.mysite.dk/{R:1}" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
    

    it triggers on both mysite.dk and mytohersite.dk. myothersite.dk gets redirected to mysite.dk

    How do i set it up so its only http://www.mysite.dk that gets redirected to https://www.mysite.dk?

  • Amir Khan 1284 posts 2741 karma points
    Mar 29, 2017 @ 15:03
    Amir Khan
    0

    Try this, these are the domains you want to force https on, the others will default to http.

    <rewrite>
    <rules>
        <rule name="Redirect non-www to www domains">
            <match url="^(.*)" />
            <conditions logicalGrouping="MatchAny">
                <add input="{HTTP_HOST}" pattern="^securedomain1.com" />
                <add input="{HTTP_HOST}" pattern="^securedomain2.com" />
                <add input="{HTTP_HOST}" pattern="^securedomain3.com" />
            </conditions>
            <action type="Rewrite" url="https://www.{HTTP_HOST}/{R:0}" />
        </rule>
    </rules>
    

    /

Please Sign in or register to post replies

Write your reply to:

Draft