model view controller - MVC - Make all URLs with a trailing slash 301 to URL without a slash? -
is there way redirect urls end in trailing slash url without?
in application_beginrequest
method in global.asax
, add following:
if (httpcontext.current.request.url.absolutepath != "/" && httpcontext.current.request.url.absolutepath.endswith("/")) { string redirect = httpcontext.current.request.url.absolutepath; redirect = redirect.remove(redirect.length - 1); response.clear(); response.status = "301 moved permanently"; response.addheader("location", redirect); response.end(); }
Comments
Post a Comment