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 to

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

  2. 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";

    This is redirect code it should work.
  3. Ray


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

    And yes it should also work well for redirecting to

    But remember because you are putting a redirect script at your start page any calls made to eath whether it is or will redirect to 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 ( to the www subdomain (,

    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 ={R:0}

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

    Hope this helps.
  5. 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