Reputation: 1362
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?
Upvotes: 2
Views: 1495
Reputation: 1390
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 =]
Upvotes: 3