View Complete Thread
  • 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!)