Need assistance rewriting app.sub.domain.com to app.sub.domain.com/app in Web FarmRSS

6 replies

Last post Jul 10, 2020 03:20 AM by Jalpa Panchal

  • Need assistance rewriting app.sub.domain.com to app.sub.domain.com/app in Web Farm

    Jun 22, 2020 12:18 PM|Elbow_Greese|LINK

    Hello,

    I'm a noob at the rewrite module and as the title says, I'm struggling with getting this rule to work properly for me.

    I need to be able to have the URL https://app.sub.domain.com get rewritten to https://app.sub.domain.com/app.  I have about 100 different app names, so I need to use a variable for that.

    This is in a web farm environment as well, so the additional standard web farm rewrite rules need to be processed as well (if I understand correctly).

    Here's what I have so far:

    <rewrite>
    <globalRules>
    <clear />
    <rule name="Append Customer Name" enabled="true" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{HTTP_HOST}" pattern="^([a-z0-9-]+)\.sub\.domain\.com$" />
    </conditions>
    <action type="Redirect" url="/{C:1}" />
    </rule>
    <rule name="ARR_API_loadbalance_SSL" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
    <match url="*" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{HTTPS}" pattern="on" />
    </conditions>
    <action type="Rewrite" url="https://API/{R:0}" />
    </rule>
    <rule name="ARR_API_loadbalance" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
    <match url="*" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
    <action type="Rewrite" url="http://API/{R:0}" />
    </rule>
    </globalRules>
    </rewrite>

    Some additional constraints I will have:

    If a user uses https://sub.domain.com/app, or https://app1.sub.domain.com/app1 the rule will not be applied

    If a user uses https://app1.sub.domain.com/app2, I need to point it to an error page.

    Right now, I'm just trying to get the app added to the end of the URL, but it seems to be in a loop because I get app/app/app... at the end.

    Any help would be appreciated!

    Thanks,

    Todd

  • Re: Need assistance rewriting app.sub.domain.com to app.sub.domain.com/app in Web Farm

    Jun 23, 2020 05:48 AM|Jalpa Panchal|LINK

    Hi,

    you could try below rule:

     <rule name="Append Customer Name" enabled="true" stopProcessing="true">
                        <match url="^\/?$" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="^([a-z0-9-]+)\.sub\.domain\.com$" />
                        </conditions>
                        <action type="Redirect" url="/{C:1}" />
                    </rule>

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
  • Re: Need assistance rewriting app.sub.domain.com to app.sub.domain.com/app in Web Farm

    Jun 23, 2020 03:32 PM|Elbow_Greese|LINK

    Thanks for the help, unfortunately I'm getting the same results.

    I did notice that when I browse to:

    app.sub.domain.com/folder/image.jpg

    the rewrite rule does work correctly and I'm redirected to:

    app.sub.domain.com/app/folder/image.jpg

    Just when I use either:  app.sub.domain.com or app.sub.domain.com/app

    I get directed to:
    app.sub.domain.com/app/app/app/app/app/app....

    It seems like it's in a loop applying the "/app".  Is there a way to have it only apply once?

    Thanks again for the help!

    Todd

  • Re: Need assistance rewriting app.sub.domain.com to app.sub.domain.com/app in Web Farm

    Jun 24, 2020 03:11 AM|Jalpa Panchal|LINK

    Hi,

    Below is my test result, the rule is working correctly on my side. I suggest you could try to remove the browser history and cache then try again to access the site.

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
  • Re: Need assistance rewriting app.sub.domain.com to app.sub.domain.com/app in Web Farm

    Jun 24, 2020 08:14 PM|Elbow_Greese|LINK

    I've cleared by history and cache and the redirect works for the app.sub.domain.com, however, now the redirect isn't working when there's an additional query string in the URL.

    As an example, app.sub.domain.com/folder/file.jpg is no longer rewritten to app.sub.comain.com/app/folder/file.jpg.

    I've also added a condition that sub.domain.com/app is not processed in the rewrite rule since we need to have legacy connections work as well.

    Here's what I have now:

    <rule name="Append Customer Name" enabled="true" stopProcessing="true">
    <match url="^\/?$" />
    <conditions>
    <add input="{QUERY_STRING}" pattern="^sub.domain.com$" negate="true" />
    <add input="{HTTP_HOST}" pattern="^([a-z0-9-]+)\.sub\.domain\.com$" />
    </conditions>
    <action type="Redirect" url="/{C:1}/{R:0}" />
    </rule>

    I've tried with and without the {R:0} at the end of the redirect action, and no change.

    Thanks!

    Todd

  • Re: Need assistance rewriting app.sub.domain.com to app.sub.domain.com/app in Web Farm

    Jun 26, 2020 09:34 AM|Jalpa Panchal|LINK

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
  • Re: Need assistance rewriting app.sub.domain.com to app.sub.domain.com/app in Web Farm

    Jul 10, 2020 03:20 AM|Jalpa Panchal|LINK

    Hi,

    Is your issue solved?

    If your issue is solved then I request you to mark the helpful suggestion as an answer. This will help other people who face the same issue.

    If your issue still exists then try to refer the solution given by the community members.

    If then also you have any further questions then let us know about it.

    We will try to provide further suggestions to solve the issue.

    Thanks for your understanding.

    Regards

    Jalpa.

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.