How to add HTTP_HOST sub-subdomain using pattern? [Answered]RSS

5 replies

Last post Nov 06, 2019 08:03 PM by scogordo

  • How to add HTTP_HOST sub-subdomain using pattern?

    Nov 05, 2019 05:09 PM|scogordo|LINK

    I have a situation where I have two URLs going to the same content. There are customizations to the code that only work with one of the urls. The URL that works has a sub-subdomain, "HR", as shown in the second step. I need all requests for http://intranet.contoso.local/sites/hr/SitePages/hr.aspx specifically  to redirect to

    http://HR.intranet.contoso.local/sites/hr/SitePages/hr.aspx. None of the other pages in the site should redirect, just this specific one:

    1. identify an HTTP_HOST and REQUEST_URI pattern for http://intranet.contoso.local/sites/hr/SitePages/hr.aspx
    2. add a sub-subdomain, http://HR.intranet.contoso.local/sites/hr/SitePages/hr.aspx

    Here is the code I plan to use, however, I am concerned that the <add input="{HTTP_HOST}" pattern="^intranet.contoso.local$" /> is going to create an endless loop.

          <rewrite>
                <rules>
     		<rule name="Force intranet.contoso.local to HR.intranet.contoso.local" enabled="false" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                             <add input="{HTTP_HOST}" pattern="^intranet.contoso.local$" />
                            <add input="{REQUEST_URI}" pattern="^/sites/hr/SitePages/hr\.aspx" ignoreCase="true" negate="false" />
                        </conditions>
                        <action type="Redirect" url="HR.intranet.contoso.local/sites/hr/SitePages/hr.aspx#" />
                    </rule>
                </rules>
            </rewrite>

    Related to https://forums.iis.net/t/1246688.aspx?replace+Protoco+and+HTTP_host+for+given+pattern (Thanks 

    Jalpa Panchal!)

  • Rovastar Rovastar

    5457 Posts

    MVP

    Moderator

    Re: How to add HTTP_HOST sub-subdomain using pattern?

    Nov 05, 2019 06:24 PM|Rovastar|LINK

    The HTTP_HOST info looks fine regular expression wise

    As always try it out on a non-production copy of your site to see what it does and walk through rewrite rules with failed request tracing.

    I would say be very wary of using that many subdomains in the rewrite. I only deal with https FQDNs but having more than x.y.z (e.g. w.x.y.z) can cause issues.

    Troubleshoot IIS in style
    https://www.leansentry.com/
  • Re: How to add HTTP_HOST sub-subdomain using pattern?

    Nov 05, 2019 07:21 PM|scogordo|LINK

    Thanks Rovastar. 

    So if someone tries to go directly to http://HR.intranet.contoso.local/sites/hr/SitePages/hr.aspx# the condition

    <add input="{HTTP_HOST}" pattern="^intranet.contoso.local$" />

    won't pick up the intranet.contoso.local in hr.intranet.contoso.local and keep looping it? 

  • Rovastar Rovastar

    5457 Posts

    MVP

    Moderator

    Re: How to add HTTP_HOST sub-subdomain using pattern?

    Nov 05, 2019 08:47 PM|Rovastar|LINK

    The ^ means that it must start with the next bit in the string. So you should be good there.

    I haven't tested it are you having problems with it?
    Troubleshoot IIS in style
    https://www.leansentry.com/
  • Re: How to add HTTP_HOST sub-subdomain using pattern?

    Nov 06, 2019 09:30 AM|Jalpa Panchal|LINK

    Hi,

    As Rovastar says having more than x.y.z (e.g. w.x.y.z) can cause issues.

    you could try below rule:

    <rule name="Force intranet.contoso.local to HR.intranet.contoso.local" enabled="true" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
    <add input="{HTTP_HOST}" pattern="^intranet.contoso.local$" />
    <add input="{REQUEST_URI}" pattern="^/sites/hr/SitePages/hr\.aspx" />
    </conditions>
    <action type="Redirect" url="http://HR.intranet.contoso.local/sites/hr/SitePages/hr.aspx" />
    </rule>

    you did some mistake like you forget to add Http in redirect URL another is you may forget to add enable the 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: How to add HTTP_HOST sub-subdomain using pattern?

    Nov 06, 2019 08:03 PM|scogordo|LINK

    Thanks Rovastar. Worked great. And yeah, we're getting rid of the sub-subdomain, but it's a process.