Prepend www to incoming domain.com is not workingRSS

13 replies

Last post Oct 01, 2019 01:13 PM by JefffRozar

  • Prepend www to incoming domain.com is not working

    Sep 07, 2019 11:11 AM|JefffRozar|LINK

    I setup a URL Rewrite Rule that redirects any incoming domain.com Pattern to redirect to https://www.domain.com/{R:0}

    I put this in ARR 3.0 in both the URL Rewrite for the ARR Server's URL Rewrite option and also in the 'Default Web Site' URL Rewrite option.

    Match URL is: WIldcards, *

    Condition is: {HTTP_HOST}, Matches the Pattern, domain.com

    Redirect (Permanent) goes to: https://www.domain.com/{R:0}

    Neither rule is working.

    Where else can I look or how can I fix this?

  • Re: Prepend www to incoming domain.com is not working

    Sep 09, 2019 07:30 AM|Yuk Ding|LINK

    Hi  JefffRozar,

    Please try this rule, it is working perfectly for me. Just ensure you are setting this rule under the website with domain "domain.com".

    </rule>
                    <rule name="prepend www" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="^domain.com$" />
                        </conditions>
                        <action type="Redirect" url="https://www.{C:0}{R:0}" redirectType="Temporary" />
                    </rule>

    Best Regards,

    Jokies Ding

    Yuk Ding

    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue.
  • Re: Prepend www to incoming domain.com is not working

    Sep 09, 2019 11:38 PM|JefffRozar|LINK

    Works perfect! Thank you! I did it within the IIS interface: http://imgsafe.org/image/6e22460a95

    I made it the first rule in my list.

  • Re: Prepend www to incoming domain.com is not working

    Sep 10, 2019 02:32 AM|Yuk Ding|LINK

    Hi JefffRozar,

    I'm so glad that the problem was resolved with my rule. It is so appreciated if you could mark the reply as answer.

    Yuk Ding

    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue.
  • Re: Prepend www to incoming domain.com is not working

    Sep 15, 2019 03:09 PM|JefffRozar|LINK

    Problem...when a user types in domain.com, in IE, for example, it prepends http:// to it, so the string is http://domain.com

    This does not get prepended with www.

    I put in an {HTTP_HOST} match as http://domain.com but it still does not work.

    The wildcard pattern does not match: http://imgsafe.org/image/f69953f242

    And the conditions pattern doesn't match either: http://imgsafe.org/image/f6a1459048

    Why?

    Also, does iisreset need to be run when a rule is changed?

  • Re: Prepend www to incoming domain.com is not working

    Sep 19, 2019 05:40 AM|Yuk Ding|LINK

    Hi JefffRozar,

    Because you are using URL regex expression under wildcards. Please change wildcard to regular expression and try again.

    Best Regards,

    Jokies Ding 

    Yuk Ding

    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue.
  • Re: Prepend www to incoming domain.com is not working

    Sep 20, 2019 12:56 PM|JefffRozar|LINK

    I don't have it set to Regular Expressions. Mine is set to Wildcards. Not sure where you got that image.

    Can you look at my screenshots? Wildcard and Conditional are not matching the Test Pattern either.

  • Rovastar Rovastar

    5445 Posts

    MVP

    Moderator

    Re: Prepend www to incoming domain.com is not working

    Sep 20, 2019 01:43 PM|Rovastar|LINK

    I think you misunderstand.

    The solution posted is for regular expressions (that is generally how we do rewrite rules)

    Wildcards use a different syntax.

    So to fix it try it in regular expressions.
    Troubleshoot IIS in style
    https://www.leansentry.com/
  • Re: Prepend www to incoming domain.com is not working

    Sep 20, 2019 05:40 PM|Yuk Ding|LINK

    Hi JefffRozar,

    I mean you should change  using:wildcard to using:regular expression. (.*)  and ^ $ is regex expression format instead of wildcard expression format.

    So if you change the expression type. the rule should start working.

    Best Regards,

    Jokies Ding

    Yuk Ding

    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue.
  • Re: Prepend www to incoming domain.com is not working

    Sep 24, 2019 05:19 PM|JefffRozar|LINK

    So I changed to:

    • Regular Expressions
    • Pattern: (.*)
    • Match {HTTP_HOST} with pattern ^domain.com$
    • And Redirect Temporary to: https://www.{C:0}{R:0}

    Still doesn't work when I put in http://domain.com

    When I edit the condition pattern of ^domain.com$, the test pattern fails when I put in http://domain.com

    But if the pattern is just domain.com, the test pattern of http://domain.com succeeds, but the rule still fails.

  • Rovastar Rovastar

    5445 Posts

    MVP

    Moderator

    Re: Prepend www to incoming domain.com is not working

    Sep 25, 2019 12:14 PM|Rovastar|LINK


    For the HTTP_HOST it does not look at the http:// part just yet the actual domain name.

    How does the rule fail? Doesn't seem to do anything? Redirect to the wrong place?

    And make sure you are using a new browsers /cleared all cache as befire you have tried a rule with a perm redirect which will stay for all time broken in your browser.
    Troubleshoot IIS in style
    https://www.leansentry.com/
  • Re: Prepend www to incoming domain.com is not working

    Sep 25, 2019 03:05 PM|JefffRozar|LINK

    It fails with a 404 when I put this exact string in a browser on a brand new VM I brought up using IE: http://domain.com

    As in this example shows, the test pattern for the condition fails: http://imgsafe.org/image/c92502ddd0

  • Re: Prepend www to incoming domain.com is not working

    Sep 27, 2019 09:13 AM|Yuk Ding|LINK

    Hi JefffRozar,

    Before you apply URL rewrite, please ensure both domain.com and www.domain.com can be accessed at the same time. 

    Then you need to clean browser cache to refresh the redirect cache.

    This rule is working on my side

    When you access domain.com, IIS return 307 response and client get redirected to https://www.domain.com.

    So you need to check whether URL has been changed and whether https://www.domain.com is available currently.

    And  the value of {HTTP_HOST} is domain.com not https://domain.com. So you shouldn't input https://domain.com in the pattern test.

    Yuk Ding

    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue.
  • Re: Prepend www to incoming domain.com is not working

    Oct 01, 2019 01:13 PM|JefffRozar|LINK

    Not sure what you mean by ensure both domain.com and www.domain.com can be accessed at the same time?

    https://www.domain.com is available and working fine. And I have a redirect of http -> https and that is also working fine.

    But when I do http://domain.com, I also get a 404.

    Does this have something to do with how my DNS A records are setup? When I ping domain.com AND www.domain.com, they both resolve to the correct public IP.