Tim Eckel
Tim Eckel

Reputation: 31

IIS redirect old domain to new domain keeping the path

This somewhat works, http://newdomain.com/link will redirect to https://www.newdomain.com/link. However, http://olddomain.com/link redirects to https://www.newdomain.com (losing the path).

<rule name="Enforce HTTPS and www.newdomain.com" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTPS}" pattern="off" />
        <add input="{HTTP_HOST}" pattern="olddomain\.com$" />
        <add input="{HTTP_HOST}" pattern="^newdomain\.com$" />
    </conditions>
    <action type="Redirect" url="https://www.newdomain.com/{R:1}" redirectType="Permanent" />
</rule>

I believe the code is correct, but it's not working when doing a domain to domain redirect. Something else in IIS is doing the redirect first and therefore not respecting this rule (probably never even getting to it).

This may not be so much of an IIS redirect question, but a question of what else could be causing this pre-redirect before this rule. I have no other rules that have anything to do with domains at all.

Any insight into this?

Upvotes: 0

Views: 533

Answers (1)

Tim Eckel
Tim Eckel

Reputation: 31

Thanks to @Dusan Bajic I figured it out.

I totally removed the redirect. When I did that, some of the redirects stopped working. However, the redirect from the old domain to the new domain still happened (and in the same way, removing the path). That allowed me to isolate the problem as outside of an IIS redirect.

Come to find out, the problem was with our load balancer. For the old domain, it was doing a redirect of its own, so the old domain never reached IIS. Once the load balancer redirect was removed, it then got to IIS and the above redirect which worked flawlessly.

So the solution to this was to remove the redirect and see if the redirect still happened. And if so, look at whatever is "up stream" that's doing the redirect. I didn't know our load balancer did redirects, but I do now!

Thanks for the assist Dusan Bajic

Upvotes: 1

Related Questions