Search code examples
iisurl-rewritingarr

Pass subdomain using IIS Url rewrite and ARR


I'm using a reverse proxy setup with AAR 3 and URL Rewrite 2.0 to change domains as follow:

App.mydomain.com/ -> localhost:8000/ Usersubdomain.mydomain.com -> localhost:8000/

Based on the subdomain I need to apply special behavior to the site (custom branding, show hide features, etc)

Using AAR/URL Rewrite can I pass the original url or original subdomain to the localhost server via query string or header?

App.mydomain.com -> localhost:8000?originalurl=app.mydomain.com


Solution

  • You can match any domain in a rule condition and reference that in the action. In below rule {C:0} matches the domain:

    <rule name="Pass domain" stopProcessing="true">
        <match url=".*" />
        <conditions trackAllCaptures="false">
            <add input="{HTTP_HOST}" pattern=".*" />
        </conditions>
        <action type="Redirect" url="http://localhost:8000?originalurl={C:0}" />
    </rule>