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. 

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

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

Add comment