Not the answer you might want to hear, but if you install SEOChecker http://soetemansoftware.nl/seo-checker(commercial plugin). You can select this by one click and also makes sure all url's are lowercase and with/without extension etc.
I did not want to use a rewrite rule because it will catch all sorts of cases that it should not.
I've written a content finder that will add trailing slash IF the content exists.
This is for Umbraco 7.5.11 so you may (but apparently not) need to change ContentFinderByNiceUrl to something that works in your version.
using System.Web;
using Umbraco.Core;
using Umbraco.Web.Routing;
namespace Terabyte.UmbracoWebsite.Infrastructure.ContentFinders
{
public class MissingTrailingSlashContentFinder: IContentFinder
{
private readonly IContentFinder _baseContentFinderByNiceUrl = new ContentFinderByNiceUrl();
public bool TryFindContent(PublishedContentRequest docRequest)
{
if (HttpContext.Current.Request.Url.LocalPath.EndsWith("/"))
{
return false;
}
if (_baseContentFinderByNiceUrl.TryFindContent(docRequest))
{
docRequest.SetRedirectPermanent(docRequest.Uri.EndPathWithSlash().ToString());
return true;
}
return false;
}
}
public class MissingTrailingSlashContentFinderApplicationStartup : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase app, ApplicationContext ctx)
{
ContentFinderResolver.Current.InsertTypeBefore<ContentFinderByNiceUrl, MissingTrailingSlashContentFinder>();
}
}
}
Add Trailing Slash Url Rewrite
I have found a rule for removing a trailing slash
<add name="noendslash"
virtualUrl="^(.*)/$"
rewriteUrlParameter="IncludeQueryStringForRewrite"
redirect="Application"
destinationUrl="~$1"
ignoreCase="true" />
but is there one for adding a trailing slash. My client wants it for "SEO" purposes?
Thanks
Simon
Take a look at this blog post:
http://umbraco.miketaylor.eu/2010/11/03/url-rewriting-and-seo/
And this code snippet:
http://snipt.net/m1ketayl0r/umbraco-seo-url-rewriting
This uses the IIS7 Rewrite module...
Cheers,
Mike
I know this is old but that first link is inaccessible and the second refers to removing the trailing slash, not adding (as was originally requested).
Here is the rewrite rule that seems to work for me:
There's an extra
negate="true" />
but apart from that seems to workI have added this in config and working fine for me
Manish
I think you can config it in Umbraco In Config->umbracoSettings.config Look for addTrailingSlash in requestHandler
I think this adds the trailing slash to links but doesn't redirect ones without links?
Not the answer you might want to hear, but if you install SEOChecker http://soetemansoftware.nl/seo-checker(commercial plugin). You can select this by one click and also makes sure all url's are lowercase and with/without extension etc.
Hope this helps,
Richard
I would definitely recommend SEOChecker - it's awesome.
This package is good except paid one
Thanks
I did not want to use a rewrite rule because it will catch all sorts of cases that it should not. I've written a content finder that will add trailing slash IF the content exists.
This is for Umbraco 7.5.11 so you may (but apparently not) need to change ContentFinderByNiceUrl to something that works in your version.
If you wish to remove duplicate slashes from your urls replace the first few lines of the TryFindContent(...) with this:
Umbraco 8 uses this rule
Hmm, I don't think I like that. I think that means many 404s will be preceded by a redirect, and I still suspect it will catch cases it shouldn't.
is working on a reply...