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);
}
}