Contact Yart for a relaxed conversation
Your Name * Message *
Your Email *  
Your Phone   
Our Phone:        03 8685 8718 (within Australia)
61 3 8685 8718 (outside Australia)
Contact Yart

Melbourne Content Management and Flash developers

 

for designers, agencies and your website

Resources / Umbraco Tips And Tricks / Redirect To A Base URL
Redirect To A Base URL In Umbraco

I had a website with multiple bindings eg

http://www.mysite.com
http://mysite.com
http://www.mysitenow.com

Using IIS, I wanted to force requests to the second two domains to redirect to http://www.mysite.com

I asked how to do this on ServerFault and got this answer. Although this would work, I decided to implement it as a Macro which as a developer I find easier. The macro is:

@{
    string url = Request.Url.ToString();
    string base_url = "www.mywebsite.com.au";
    string server_name = Request.ServerVariables["SERVER_NAME"];

    if (server_name.IndexOf(base_url) != 0)
    {
      url = url.Replace(server_name, base_url);
      Response.Status = "301 Moved Permanently";
      Response.AddHeader("Location", url);
    }
}

The latest at Yart
Search: