Wednesday 9 October 2013

Redirecting .co.uk to .com with ASP.net MVC IIS7 URL ReWrite 2.0

I recently started work on a new website, where I’ve purchased the .co.uk and .info domain names. However, I wanted to redirect people automatically to the main .com domain.
As my host supports the IIS7 URL ReWrite 2.0 moduke, adding the following section to the primary web.config file solved this for me;
   1: <rewrite>

   2:       <rules>

   3:         <rule name="RedirectToWWW1" stopProcessing="true">

   4:           <match url=".*" ignoreCase="true" />

   5:           <conditions logicalGrouping="MatchAny">

   6:             <add input="{HTTP_HOST}" pattern="^mydomain.co.uk$" />

   7:             <add input="{HTTP_HOST}" pattern="^mydomain.info$" />

   8:             <add input="{HTTP_HOST}" pattern="^www.mydomain.co.uk$" />

   9:             <add input="{HTTP_HOST}" pattern="^www.mydomain.info$" />

  10:           </conditions>

  11:           <action type="Redirect" url="http://www.mydomain.com/{R:0}" redirectType="Permanent" />

  12:         </rule>

  13:       </rules>

  14:     </rewrite>

No comments:

Post a Comment