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?
Asked
Active
Viewed 49 times
-1

Joel Coehoorn
- 399,467
- 113
- 570
- 794

MBA
- 35
- 1
- 6
-
I think you need to look into .htaccess redirects – bwoogie Feb 11 '17 at 17:36
-
Why don't you just set the cookie for `.example.com`? – mrun Feb 12 '17 at 08:50
3 Answers
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