Created
June 20, 2012 10:24
-
-
Save karlitros/2959247 to your computer and use it in GitHub Desktop.
Avoiding duplicate content due to case-sensitive URLs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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