skip to Main Content

I run a small ASP.NET4 website on IIS. I recently changed the domain name from ‘olddomain.com’ to ‘newdomain.com’. The change was made through Plesk. After making the change I added ‘olddomain.com’ as a domain alias in plesk so that traffic would still route through to the website on the old domain.

This is fine so far. The website resolves on both old and new URLs.

However, now I would like to set up 301 redirects everywhere so that any request for olddomain.com are forwarded to newdomain.com instead. None of the website pages have changed – it’s just a simple change of domain name.

I’ve added this to the web.config file:

<rewrite>
    <rules>
        <rule name="Redirect all to different domain" stopProcessing="true">
            <match url=".*" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^olddomain.com$" />
            </conditions>
            <action type="Redirect" url="http://www.newdomain.com/{R:0}" redirectType="Permanent" />
        </rule>
    </rules>
</rewrite>  

But it doesn’t seem to have any impact; when I load olddomain.com in the browser it just loads the website without redirecting to newdomain.com.

Can anyone suggest what I’ve done wrong here and how to get the 301 to work?

Thanks

2

Answers


  1. Chosen as BEST ANSWER

    This works:

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

  2. You can set 301 permanent redirect from IIS also.

    If http redirection is enabled on old server then you have to put new web config with the contents –

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <httpRedirect enabled="true" destination="http://mynewsite.com/" httpResponseStatus="Permanent" />
        </system.webServer>
    </configuration>
    

    Let me know if it helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search