IIS Redirection – How to Redirect One Domain to Another

iisredirection

On the same website in IIS, we have 2 bindings with domain names "old.example.org" and "new.example.org".

When someone calls "https://old.example.org/abc/?xyz=123", I would like to send a permanent redirect to "https://new.example.org/abc/?xyz=123"

If I use the Http Redirect module of IIS, I get an infinite redirection because both domain name target the same website.

I could do it in the application code, but really it would be much better to do it in IIS or somewhere before, is it possible to set this kind of permanent redirect at a another level than IIS or differently in IIS to avoid infinite loop ?

Best Answer

You can use URL rewrite module

<rule name="CanonicalHostNameRule" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^(.*)$" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^old.example.org$" />
          </conditions>
          <action type="Redirect" url="https://new.example.org/{R:1}" />
        </rule>
Related Topic