-1

I have any asp.net mvc website, and I want to open it as www.example.com instead of example.com. I want to redirect every user who uses example.com to www.example.com. The reason why I am doing this is to maintain the cookies. As currently 2 different cookies sets one works for www.example.com and the other works for example.com. How can I do this?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
MBA
  • 35
  • 1
  • 6

3 Answers3

0

This needs to be done in web.config, not .htaccess. There's a similar question with a great response here.

Community
  • 1
  • 1
Rob Reagan
  • 7,313
  • 3
  • 20
  • 49
0

You can use the IIS URL Rewrite Module for that. But it is not installed on the server by default. When installed you can create a rule in the Web.Config file of your site.

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Redirect to www" stopProcessing="true">
        <match url=".*" ignoreCase="true" />
        <conditions>
          <add input="{HTTP_HOST}" pattern="^traindb.nl" />
        </conditions>
        <action type="Redirect" url="http://www.traindb.nl/{R:0}" redirectType="Permanent" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>
VDWWD
  • 35,079
  • 22
  • 62
  • 79
0

You could configure the redirection from example.com -> www.example.com at the DNS or even in IIS settings.

MAli
  • 1