Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i configure in web.config a 301 permanent redirect?

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.

like image 303
OrElse Avatar asked Dec 16 '22 09:12

OrElse


1 Answers

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>
like image 181
Pa.M Avatar answered Dec 28 '22 06:12

Pa.M