Found out about this today. Did you get anywhere with the investigation how to change this to 301?
If you take a look at the method ConvertToInternalInternal inside the FriendlyUrlRewriteProvider
if (!url.Path.EndsWith("/"))
{
url.Path += "/";
HttpContext.Current.Response.Redirect(url.Path + url.Query + url.Fragment);
}
Guess you can make your own and override that redirect
Thanx Anders. It worked for Episerver 5 version. In 6R2 FriendlyUrlRewriteProvider is changed so I cannot find suitable location to check and add 301. If anybody has a clue, it would help.
Regards
Hi, I have the same problem. Status code in case of missing trailing slash instead of 302 should be 301. Found place where trailing slash is analysed:
EPiServer.Web.FriendlyUrlRewriteProvider, ConvertToInternalInternal method
But I could not figure out the correct place to change status code. Can you please give me a clue.
Thanks in advance,
Artem
global.asax, EndRequest event
private void Global_EndRequest(object sender, EventArgs e)
{
//EPiServer in case of missing trailing slash in the url returns status code 302. This is not good for the SEO.
//Url with missing trailing slash is exceptional on the page and should be fixed by renderer of such urls.
//Found place where trailing slash is analysed: EPiServer.Web.FriendlyUrlRewriteProvider, ConvertToInternalInternal method
/*
if (page.LinkType == PageShortcutType.External)
{
internalObject = new RedirectPageReference(page.PageLink);*****************************
url.Uri = new Uri(page.LinkURL);
return true;
}
+++++++++++++++ if (!url.Path.EndsWith("/") && string.IsNullOrEmpty(UrlRewriteProvider.FriendlyUrlExtension)) +++++++++++++++
{
internalObject = new RedirectPageReference(page.PageLink);*****************************
url.Path = url.Path + "/";
return true;
}
*/
//As you can see internalObject is initialized with RedirectPageReference, and objects of this class
//is used in: EPiServer.Web.UrlRewriteModule, HttpUrlRewriteToInternal method
/*
if (Global.UrlRewriteProvider.ConvertToInternal(e.Url, out obj2))
{
if (obj2 is RedirectPageReference) ******************************
{
HttpContext.Current.Response.Redirect((string) e.Url, true);++++++++++++
return;
}
*/
//Redirect method returns 302 status code.
//following code fixes that
int statusCode = HttpContext.Current.Response.StatusCode;
if (statusCode == 302)
{
//urlrewrite module redirected and page (IHttpHandler) was not executed
if (HttpContext.Current.Handler == null)
{
PageReference currentPage;
string internalUrl = CmsUrlHandler.ConvertToInternalUrl(HttpContext.Current.Request.RawUrl, out currentPage);
if (currentPage != null && currentPage != PageReference.EmptyReference && currentPage is RedirectPageReference)
{
HttpContext.Current.Response.StatusCode = 301;
}
}
}
}
The Urlrewriter is producing a 302 redirect in a very specific scenario:
http://www.baigent.com/Portfolio is redirected to http://www.baigent.com/Portfolio/ in this way.
for SEO reasons we obviously would prefer this to be a permanent redirect... after initial research into this I'm not entirely sure if this is the the UrlRewrite's doing or if IIS is to blame.
Note the rewrite section is pretty much standard: