Simple Ways to Redirect Old Domain to New Domain in IIS

You will undoubtedly address the migration issue while changing the domain name for your website. You cannot just disable DNS on your previous site since this would result in search engines removing your indexed content. When a person accesses an old URL, you should link them to the new URL in order to inform search engines that you now have a new domain name.

Take as an example; the previous domain was dotnetblog.asphostportal.com, and the current one is asphostportal.net. So basically for requests to the old dotnetblog.asphostportal.com, such as:

https://dotnetblog.asphostportal.com/3-ssl-types-that-you-need-to-know/

Then, we will redirect it to:

https://asphostportal.net/3-ssl-types-that-you-need-to-know/

This just keeps the rest of the URL the same while changing the domain name.

To implement this feature, we need to install the URL Rewrite module on IIS: http://www.iis.net/downloads/microsoft/url-rewrite

For every website managed by IIS, it can assign URL rewrite or redirect rules individually. You can use both GUI and manually edit web.config to modify the rules.

My set up for changing the domain name would be:

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

The pattern is using a regular expression, to check if {HTTP_HOST} is equal to dotnetblog.asphostportal.com.

the {R:1} in the action means whatever is in the URL behind the domain name itself.

Redirect and Rewrite are the two options that we offer. Rewrite simply keeps the HTTP status code. For instance, if you have a “/a/b/c.html” and rewrite it into “/d.html,” Rewrite will simply make it appear as though you are accessing /d.html and its content is output using c.html. Redirect will result in an HTTP 301, which will notify the search engine about the domain change.

If you have any additional rules, pay attention to the sequence since they will be handled in that order.

You may refer to Microsoft documentation for more usage: http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

Now that we have a 301 redirect, the search engine’s index will also be updated. You can terminate DNS on your former domain after a few of months.

Conclusion

In previous post, we have written tutorial about how to redirect old URL to new URL using .NET. This article might be little bit different since you can access IIS to make change.

Are you looking for an affordable and reliable Asp.net core hosting solution?

Get your ASP.NET hosting as low as $1.00/month with ASPHostPortal. Our fully featured hosting already includes

  • Easy setup
  • 24/7/365 technical support
  • Top level speed and security
  • Super cache server performance to increase your website speed
  • Top 9 data centers across the world that you can choose.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *