Comment on 301 Redirect Htaccess by Martin Kristiansson.

301 Redirect Htaccess I did a solution in Page_Load event in my masterpage and it works flawless =)

    protected void Page_Load(object sender, EventArgs e)
    {
        // Permanently 301 Redirect non www. requests
        if (!Request.Url.AbsoluteUri.Contains("www")) // Checks if the url does not contain www
        {
            Response.Status = "301 Moved Permanently";
            if (Request.Url.AbsolutePath.ToString() == "/default.aspx") // If root do not write /default.aspx
                Response.AddHeader("Location", "http://www.domain.com");
            else
                Response.AddHeader("Location", "http://www.domain.com" + Request.Url.AbsolutePath.ToString()); // If not root write the full path & query
        }
    }