Redirect root domain to www subdomain

Discussion in 'General troubleshooting' started by jameszhao00, Feb 23, 2010.

  1. Hi,

    What's the proper way to redirect the root domain to the www subdomain? I tried IIS manager's Redirect tool, but that didn't redirect evecakes.com to www.evecakes.com

    Oh and by the way I'm using ASP.NET MVC, so there's some built-in rewrite there. Donno if it's relevant.

    Thanks
     
  2. Ray

    Ray

    On your startup page and at the top of the startup page try writing this code.


    <script runat="server">
    private void Page_Load(object sender, System.EventArgs e)
    {
    Response.Status = "301 Moved Permanently";
    Response.AddHeader("Location","http://www.mydomainname.com");
    }
    </script>

    This is redirect code it should work.
     
  3. Ray

    Ray

    You do not need to created subdomain www.evecakes.com it is already part of the header entry and A record.

    And yes it should also work well for redirecting to www.evecakes.com/a/b/c

    But remember because you are putting a redirect script at your start page any calls made to eath whether it is evecakes.com or subdomain.evecakes.com will redirect to www.evecakes.com/a/b/c. If you want conditions to take affect then obviously your redirect script will become more complicated. You may also end up use the URL Rewrite module on IIS if your redirect rules becomes too complicated.
     
  4. Thank you. I ended up going with IIS URL Rewrite's Redirect though (took me an hour to figure it out... that URL Rewrite UI's concept/metaphore was not well designed)

    To redirect root domains (http://domain.com) to the www subdomain (http://www.domain.com),

    In IIS Manager => Url Rewrite

    I added a URL Redirect rule

    pattern = (.*)

    Added a Condition
    Condition Input = {HTTP_HOST},
    Matches the pattern
    Pattern =^domain\.com$

    Action Type = Redirect
    Redirect URL = http://www.domain.com/{R:0}

    I donno why that worked exactly (R:0 returns the full URL), but it did.

    Hope this helps.
     
  5. Ray

    Ray

    Don't feel bad. I still have a hard time with it also. Especially when it comes to inputting the pattern. That regular expression is hard for me to get my mind to wrap around.
     

Share This Page