Redirect Subdomain URL to another SubDomain in IIS

14,200

Solution 1

I think you need to create a separate site with host bindings for report.usapartners.com (the fake site) in IIS. This is going to be a stub site (it will still need a path on the disk, but it's only going to have a web.config in there) which will just host a redirect rule.

Now click on HTTP Redirect for that site in IIS and tick Redirect requests to this destination and put http://reporting.usapartners.com in the textbox. Then tick Redirect all requests to exact destination (instead of relative to destination), don’t tick the next one and then choose Status Code Permanent (301).

If you want it to redirect and keep the subdirectories and/or query string, then you can change the contents of the textbox to be http://reporting.usapartners.com$S$Q. Note that there is no trailing slash in this case. The $S preserves the sub directories and the $Q preserves the query string.

Solution 2

Your rule is causing a redirect loop.

Observe what your rule does:

  • Match any given URL (this includes "/", "/something", "/something/another.html", etc.)
  • If the host name ISN'T "report.usapartners.com"
  • Redirect permanently the request to "http://reporting.usapartners.com"

So, as you see, as soon as the user is redirected to the reporting subdomain, it gets redirected again to reporting, because hostname isn't "report.usapartners.com".

The key here is the negate="true" attribute on the rule condition. Remove it or set it to false and you are good to go.

Edit:

You are almost there.

The real solution would be to change the host name on the rule to the desired host, keeping the negate true, so your rule would do:

  • Match any given URL (this includes "/", "/something", "/something/another.html", etc.)
  • If the host name ISN'T "reporting.usapartners.com"
  • Redirect permanently the request to "http://reporting.usapartners.com"

Code:

...
<add input="{HTTP_HOST}" pattern="reporting.usapartners.com" negate="true" />
...
Share:
14,200
Slinky
Author by

Slinky

Software developer for a large music retailer

Updated on August 05, 2022

Comments

  • Slinky
    Slinky over 1 year

    I need to redirect a "fake" sub domain to a real subdomain in IIS 7.5. The reason is that the marketing department doesn't want to use the actual website address in print pieces.

    Actual site URL:

    reporting.usapartners.com

    Marketing dept wants report.usapartners.com (fake) to redirect to reporting.usapartners.com (real)

    Again, report.usapartners.com does not exist, only reporting.usapartners.com exists

    Here is what I tried

    I added a binding in IIS, for the site reporting.usapartners.com. I added report.usapartners.com as the host name and used the reporting.usapartners.com IP address

    Then I went into reporting.usapartners.com web.config and added this:

    <rewrite>
        <rules>
            <rule name="report" stopProcessing="true">
              <conditions logicalGrouping="MatchAll">
                <add input="{HTTP_HOST}" pattern="report.usapartners.com" negate="false" />
              </conditions>
              <action type="Redirect" url="http://reporting.usapartners.com" appendQueryString="false" redirectType="Permanent" />
            </rule>
        </rules>
    </rewrite>
    

    Looks like my solution creates an alias that cannot be redirected to.

    Am I even approaching this problem correctly? Seems like it should be a simple problem to solve but perhaps not? Any ideas are welcomed and appreciated.

    Thanks