views:

203

answers:

2

I have an application written on ASP.NET MVC (V 1.0). The application runs on IIS7 and the DNS is provided by GoDaddy.

I would like to forward any request that comes from http://mydomain.com/ctrlr/act/value to a URL of this form: http://WWW.mydomain.com/ctrlr/act/value

Basically, I want to add WWW to the Host-name if someone tries to reach http://mydomain.com

What would be the best way to do this?

+2  A: 

I think you will find an answer that suits from this question

I would agree with your idea of forcing the use off www, as though SO decided to use it I do believe they regretted when tweaking performance for cookies and having to use sstatic.net instead of images.stackoverflow.com say.

To save you a redirect here is gist of what you need to do.

Here’s the IIS7 rule to add the WWW prefix to all incoming URLs. Cut and paste this XML fragment into your web.config file under

<system.webServer> / <rewrite> / <rules>


<rule name="Add WWW prefix" >
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain\.com" />
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:1}"
    redirectType="Permanent" />
</rule>
dove
A: 

You can use Url Rewriter from Code Plex. You can force everything to www.domain.com by doing the following:

RewriteCond %{HTTP_HOST} !^(www).*$ [NC]
RewriteRule ^(.*)$ http://www.%1$1 [R=301]

Or if you want to make it more specific for your domain

RewriteCond %{HTTP_HOST} !^www.mydomain.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com$1 [R=301]

This also supports a whole bunch of other rewriter functions provided by mod_rewrite.

Nick Berardi