6

I would love to use web.config to do the 301 redirection from an old domain to another. How could i do that?

In your answers, please keep in mind that the IIS is v7 and

i would not like to use any 3rd party dll's like urlrewriteing.net etc or use ASP.NET code or configure the IIS,for that.

I am sure this can be done, but how?

UPDATE: I tried the answer of Parvesh's but i have a feeling the is not "officially" supported OR i am making something else terribly wrong.

OrElse
  • 9,709
  • 39
  • 140
  • 253

1 Answers1

14

you will need the URL rewriting module installed under IIS and then you can use this in side web.config.

<configuration>
<system.webServer>
<rewrite>
  <rules>
    <rule name="Redirect to WWW" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^domain.com$" />
      </conditions>
      <action type="Redirect" url="http://www.domain.com/{R:0}"
           redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>
</system.webServer>
</configuration>
Pa.M
  • 1,392
  • 1
  • 10
  • 15
  • Excuse me but what exactly do you mean by "URL rewriting module"? (That is great but i have the feeling that the "rewrite" rule is not officially supported) – OrElse Sep 09 '11 at 08:36
  • 1
    The url rewrite module is an officially supported Microsoft plugin to IIS 7. You can install it using the Web Platform Installer, or from their website. Info here: http://www.iis.net/download/urlrewrite – JonNeale Sep 09 '11 at 09:17
  • Actually what i did not understand is these curly hair under rewrite in VS 2010 – OrElse Sep 09 '11 at 10:53
  • intellisence might not be working for the URL rewriter module – Pa.M Sep 09 '11 at 11:05
  • I had a problem with Google AdSense that only worked on www. Now everything works perfect. Thanks – Maxali Jan 19 '13 at 15:47
  • How would I do the opposite? All users goint to http://www.domain.com should be redirected to http://domain.com? – Magnus Karlsson Dec 19 '13 at 11:07