Skip to content

Instantly share code, notes, and snippets.

@karlitros
Created June 20, 2012 10:24
Show Gist options
  • Save karlitros/2959247 to your computer and use it in GitHub Desktop.
Save karlitros/2959247 to your computer and use it in GitHub Desktop.
Avoiding duplicate content due to case-sensitive URLs
protected void Application_BeginRequest(object sender, EventArgs e)
{
//If upper case letters are found in the URL, redirect to lower case URL.
if (Regex.IsMatch(HttpContext.Current.Request.RawUrl.ToString(), @"[A-Z]") == true)
{
if (Request.HttpMethod == "GET" && !(Request.RawUrl.Contains(".axd")))
{
string LowercaseURL = HttpContext.Current.Request.RawUrl.ToString().ToLower();
Response.Clear();
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", LowercaseURL);
Response.End();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment