NopStartup.csremove more than 1 //// on the URL and it works perfectly fine.
public void Configure(IApplicationBuilder application)
{
//var rewriteOptions = new RewriteOptions()
//.AddRedirect(@"^(.*?)/{2,}$", "$1"); // Redirect URLs with multiple slashes to the normalized URL
var rewriteOptions = new RewriteOptions()
.AddRedirect(@"^(.*?)/{2,}$", "$1") // Redirect URLs with multiple slashes to normalized URL
.Add(ctx =>
{
var request = ctx.HttpContext.Request;
var originalPath = request.Path.Value;
var path = originalPath;
// Now, check for and remove trailing slash if not the root "/"
// First, normalize the path: convert to lowercase.
path = path.ToLowerInvariant();
// Then, remove trailing slash if necessary. Apply this after converting to lowercase to ensure it's effective.
var newPath = (path.Length > 1 && path.EndsWith("/")) ? path.TrimEnd('/') : path;
// Only redirect if the new path is different from the original
if (newPath != originalPath)
{
var newUrl = $"{newPath}{request.QueryString}";
ctx.HttpContext.Response.Redirect(newUrl, permanent: true);
}
});
application.UseRewriter(rewriteOptions);
application.UseResponseCaching();
}
However, if the URL =
https://www/abc.com/product123/
It remains
https://www/abc.com/product123/
What is the issue why won't it remove the trailing / and any other solution?