Handling URLs with Inconsistent Casing

Follow

Agility.Web SDK will route pages regardless of casing. Page routing in Agility is not case sensitive. While this can be convenient, it can also pose an SEO issue with duplicate URLs, or reporting issues for analytics.

Agility recommends forcing all URLs to be lowercase only. In order to do this for a .NET site, you can add a URL rewrite rule in your web.config or implement the following code in your Global.asax.cs file:

 protected void Application_BeginRequest(object sender, EventArgs e)
{
//START - CUSTOM CODE FOR UPPERCASE to LOWERCASE REDIRECT (301)
//if current URL contains any uppercase letters
string url = Request.Url.PathAndQuery;
string lowerUrl = url.ToLowerInvariant();

//ignore ecms requests and other content related requests
if (url.Contains("ecms.ashx") ||
url.Contains("ecmsrss.aspx") ||
url.Contains("/FormHandler/Save") ||
url.Contains("/AdScriptResponsive/") ||
url.EndsWith(".png") ||
url.EndsWith(".jpg") ||
url.EndsWith(".css") ||
url.EndsWith(".js") ||
url.Contains(".svc"))
{

//do nothing let the request go through

} else if (url != lowerUrl) {

Response.Clear();

Response.RedirectPermanent(lowerUrl);
}

//END - CUSTOM CODE FOR UPPERCASE to LOWERCASE REDIRECT (301) }

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.