Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forwarding http://mydomain.com/ctrlr/act/val to http://WWW.mydomain.com/ctrlr/act/val

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.example/ctrlr/act/value to a URL of this form: http://WWW.mydomain.example/ctrlr/act/value

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

What would be the best way to do this?

like image 280
xraminx Avatar asked Sep 25 '09 12:09

xraminx


2 Answers

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 Stack Overflow 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.example/{R:1}"
            redirectType="Permanent" />
  </rule>
like image 127
dove Avatar answered Oct 16 '22 07:10

dove


You can use Url Rewriter from Code Plex. You can force everything to www.domain.example 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.example$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.example$1 [R=301]

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

like image 22
Nick Berardi Avatar answered Oct 16 '22 07:10

Nick Berardi