301 Redirect all Pages to New Domain Pages for Asp.Net MVC Application

If you are changing your domain name and want to redirect all your old domain URL’s to a new domain, add the below rewrite rule to your old domain Web.config file under system.webServer tag. 

<system.webServer>
    <rewrite>
      <rules>
        <rule name="DomainNameChangeRule">
          <match url="^(.*)$" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^newdomain.com$" />
          </conditions>
          <action type="Redirect" url="http://newdomain.com/{R:1}" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>

After adding above rule to Web.config, all your old domain pages are redirected to new domain permanently (i.e, 301 redirect).

Add comment