Copied to clipboard

Flag this post as spam?

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


  • Nanou 11 posts 91 karma points
    Jun 18, 2023 @ 07:48
    Nanou
    0

    Why does this redirect to www not work?

    Hi

    I have published my website and added these IIS rewrite rules in my web.config.

    The one for HTTPS works but the other one for www does not. Does anybody knows what I am doing wrong? This code comes from the Umbraco documentation. I am working on Umbraco 11.

    <rewrite>
            <rules>
                <rule name="HTTP to HTTPS redirect" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                        <add input="{HTTP_HOST}" pattern="localhost" negate="true" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
                </rule>
                <rule name="Redirect to www prefix" stopProcessing="true">
                  <match url=".*" />
                  <conditions>
                    <add input="{HTTP_HOST}" pattern="^www\." negate="true" />
                    <add input="{HTTP_HOST}" pattern="^localhost(:[0-9]+)?$" negate="true" />
                    <add input="{HTTP_HOST}" pattern="\.umbraco\.io$" negate="true" />
                  </conditions>
                  <action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" />
                </rule>
            </rules>
          </rewrite>
    

    Any help is much appreciated!

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Jun 18, 2023 @ 13:06
    Huw Reddick
    0

    Hi Nanou,

    I think something like this should work

    <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="^[^www]" />
        <add input="{HTTP_HOST}" matchType="Pattern" 
              pattern="^localhost(:\d+)?$" negate="true" />
    </conditions>
    
  • Nanou 11 posts 91 karma points
    Jun 19, 2023 @ 17:25
    Nanou
    0

    That does not seem to work either :(

    <rules>
            <rule name="HTTP to HTTPS redirect" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                    <add input="{HTTP_HOST}" pattern="localhost" negate="true" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
            </rule>
            <rule name="Redirect to www prefix" stopProcessing="true">
              <match url=".*" />
              <conditions logicalGrouping="MatchAll">
                <add input="{HTTP_HOST}" pattern="^[^www]" />
                <add input="{HTTP_HOST}" matchType="Pattern" 
                      pattern="^localhost(:\d+)?$" negate="true" />
              </conditions>
              <action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" />
            </rule>
        </rules>
    

    It just pasting this in the web.config right?

Please Sign in or register to post replies

Write your reply to:

Draft