ITmeze - IT world server like cyprus meze

Redirect to new domain after rebranding with IIS Url Rewrite Module

ITmeze

Client has a bunch of domains and and websites. Because They have decided to change company's name recently I was asked to proceed with chanage of domain names as well. After few weeks of constantly informing visitors about planned changed We decided that it is a good time to abandon old domains and redirect visitors to new ones. In order to "be okay" with google (their page ranks, indexed pages and so on) we make those redirects permanent (301 Moved Permanently as a response status code). As all of the websites are hosted on IIS 7 I have decided to use URL Rewrite Module for the job. First of all - make sure You have Url rewrite module installed on Your server machine. Secondly, You need to update web.config file to something like the one that (assuming old-name):
  <system.webServer>
        ......
        <rewrite>
            <rules>
                <clear />
                <rule name="rebranding" enabled="false" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
                        <add input="{HTTP_HOST}" pattern="(.*)old-name(.*)" />
                    </conditions>
                    <action type="Redirect" url="http://{C:1}new-name{C:2}/{ToLower:{R:1}}" appendQueryString="true" />
                </rule>                
            </rules>
        </rewrite>
  </system.webServer>
You can do that in IIS manager as well. Some explanation here:
  • match url="(.*)" - matches all request
  • trackAllCaptures="true" - will enable to use captured grups in our redirect url
  • (.*)old-name(.*) - matches each HTTP_HOST that has 'old-name' within, like: ar.old-name.com or www.old-name.ru
  • http://{C:1}new-name{C:2}/{ToLower:{R:1}} - redirected url, R:1 stands for matches from and C:1 and C:2 matches those from conditions, ToLower changes text to lower case letters
  • appendQueryString="true" - will append query string to newly generated url
Have fun

Tags: [web development]

Copyright 2013 © ITmeze

comments powered by Disqus