IIS redirect subdomain to a new domain

Sven Rutten 96 Reputation points
2021-07-24T16:03:04.427+00:00

Hello

I have a MVC Site which I want to redirect.
Currently it is running on a subdomain.
How can I now redirect the site to a domain?

https://subdomain.olddomain.com/MyClass/?Wicked=true

to

https://newdomain.com/MyClass/?Wicked=true

So subdomain.olddomain.com should be replaced with newdomain.com

Tried:

    <system.webServer>
        <rewrite>
            <rules>
                <rule name="redirect" stopProcessing="true">
                    <match url="^(.*)$" />
                    <action type="Redirect" url="https://newdomain.com" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="subdomain.olddomain.com" />
                    </conditions>
                </rule>
            </rules>
        </rewrite>
    </system.webServer>

this is redirecting

https://subdomain.olddomain.com/MyClass/?Wicked=true

to

https://newdomain.com/?Wicked=true

instead of

https://newdomain.com/MyClass/?Wicked=true

What am I missing?

Second attempt was using HTTP Redirect:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <httpRedirect enabled="true" destination="https://newdomain.com$S$Q" exactDestination="true" httpResponseStatus="Permanent" />
    </system.webServer>

</configuration>

Doesnt work either (loading forever)

Thanks

Internet Information Services
0 comments No comments
{count} votes

Accepted answer
  1. Sven Rutten 96 Reputation points
    2021-07-24T18:43:23.157+00:00

    This fixed it:

           <rewrite>
                <rules>
                    <rule name="redirect" stopProcessing="true">
                        <match url="^(.*)$" />
                        <action type="Redirect" url="https://newdomain.com/{R:0}" appendQueryString="true" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="^subdomain.olddomain.com$" />
                        </conditions>
                    </rule>
                </rules>
            </rewrite>
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.