I am doing the SEO-optimization of my site and currently working with URLs. I've already removed the last slash and added redirection from
Now I want to remove all extra-slashes from my URL: This URL :
www.exaple/about///graduation
should redirect to
www.example/about/graduation.
I found similar questions in SO, but they seems to be asked in context of pure ASP.NET. Using System.Uri to remove redundant slash
Remove additional slashes from URL
How can I implement the same in MVC5?
-
Have you seen this post? stackoverflow.com/questions/12004223/…Colonel_Custard– Colonel_Custard2016年05月19日 12:03:49 +00:00Commented May 19, 2016 at 12:03
1 Answer 1
Use a Code-behind redirect in your Global.asax like this;
protected void Application_BeginRequest(object sender, EventArgs e)
{
string requestUrl = Request.ServerVariables["REQUEST_URI"];
string rewriteUrl = Request.ServerVariables["UNENCODED_URL"];
if (rewriteUrl.Contains("//") && !requestUrl.Contains("//"))
Response.RedirectPermanent(requestUrl);
}
I got this code from This Post, I hope that's useful to you =]
3 Comments
/Error/NotFound?404;http://localhost:81/e/e/e/e, see the // in http:// and then redirect to the original url, causing an infinite redirect loop.