locked
Using web.config to force https + www without trailing slash. RRS feed

  • Question

  • User1633968479 posted

    Small problem I ran into trying to create rewrite rules to meet following requirements:

    All incomming request should consist of "https://", "www" and should have no trailing slashes. I've tried a few possible solutions, but not one could meet up to all three requirements. Could anyone help me out here? What I have so far is:

    <rules>
            <clear/>
          <rule name="Redirect to https://www" patternSyntax="ECMAScript" stopProcessing="true">
            <match url=".*"></match>
            <conditions logicalGrouping="MatchAny">
              <add input="{HTTP_HOST}" pattern="^mydomain.be$"></add>
              <add input="{HTTPS}" pattern="off"></add>
            </conditions>
            <action type="Redirect" url="https://www.mydomain.be/{R:0}" redirectType="Permanent"></action>
          </rule>
          <rule name="Remove trailing slash" stopProcessing="true">
            <match url="(.*)/$" />
            <conditions>
              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
              <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Redirect" redirectType="Permanent" url="https://www.mydomain.be/{R:1}" />
          </rule>
    
          </rules>

    But that doesn't seem to work for me...

    Wednesday, January 24, 2018 6:07 PM

All replies

  • User283571144 posted

    Hi johnyM456,

    All incomming request should consist of "https://", "www" and should have no trailing slashes. I've tried a few possible solutions, but not one could meet up to all three requirements. Could anyone help me out here? What I have so far is:

    According to you description, I have some confused.

    Do you mean you want the rule start with https:// www or it could be anywhere in the url?

    In my opinion, we will force the url start with the "https://www" and make sure there  are no trailing slashes.

    If this is your requirement, I suggest you could consider using below regex:

    ^https://www[^/].*$

    If this doesn't match your requirement, please provide some example about which url will pass and which url will fail.

    Best Regards,

    Brando

    Thursday, January 25, 2018 4:34 AM