Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • sim0n20 7 posts 27 karma points
    Aug 03, 2011 @ 14:12
    sim0n20
    0

    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

     

  • Mike Taylor 155 posts 352 karma points
    Aug 03, 2011 @ 15:02
    Mike Taylor
    0

    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

     

     

     

  • Matthew Kirschner 322 posts 603 karma points
    May 17, 2016 @ 15:23
    Matthew Kirschner
    0

    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:

    <rule name="AddTrailingSlashRule1" stopProcessing="true">
        <match url="(.*[^/])$" />
        <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{URL}" pattern="/umbraco_client" negate="true" />
            <add input="{URL}" pattern="/umbraco" negate="true" />
            <add input="{URL}" pattern="/install" negate="true" />
            <add input="{URL}" pattern=".axd" negate="true" />negate="true" />
        </conditions>
        <action type="Redirect" url="{R:1}/" />
    </rule>
    
  • Manish 372 posts 906 karma points
    May 18, 2016 @ 06:13
    Manish
    0

    I have added this in config and working fine for me

    <!-- Enforces Trailing Slashes for consistent URLs -->
    <rule name="AddTrailingSlashRule1" stopProcessing="true">
    <match url="(.*[^/])$" />
    <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      <add input="{REQUEST_URI}" pattern="^/umbraco/" negate="true" />
    
    </conditions>
      <action type="Redirect" url="{R:1}/" />
    </rule> 
    

    Manish

  • Yakov Lebski 231 posts 928 karma points
    May 18, 2016 @ 06:36
    Yakov Lebski
    0

    I think you can config it in Umbraco In Config->umbracoSettings.config Look for addTrailingSlash in requestHandler

  • Richard Soeteman 3593 posts 10920 karma points MVP
    May 18, 2016 @ 06:56
    Richard Soeteman
    0

    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

  • Mike Taylor 155 posts 352 karma points
    May 18, 2016 @ 07:00
    Mike Taylor
    0

    I would definitely recommend SEOChecker - it's awesome.

  • Manish 372 posts 906 karma points
    May 18, 2016 @ 07:10
    Manish
    0

    This package is good except paid one

    Thanks

  • Murray Roke 452 posts 839 karma points c-trib
    May 01, 2019 @ 21:21
    Murray Roke
    0

    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>();
            }
        }
    }
    
  • Murray Roke 452 posts 839 karma points c-trib
    May 01, 2019 @ 22:08
    Murray Roke
    0

    If you wish to remove duplicate slashes from your urls replace the first few lines of the TryFindContent(...) with this:

            var path = HttpContext.Current.Request.Url.LocalPath;
            var rawPath = HttpContext.Current.Request.ServerVariables["UNENCODED_URL"]
                    .Split(new[] {'?'}, StringSplitOptions.RemoveEmptyEntries)
                    .First()
                ;
    
            if (path.EndsWith("/") && rawPath.Contains("//") == false)
            {
                return false;
            }
    
  • Lev Nuznyy 17 posts 120 karma points
    May 02, 2019 @ 02:34
    Lev Nuznyy
    0

    Umbraco 8 uses this rule

    <rule name="Add trailing slash" stopProcessing="true">
              <match url="(.*[^/{2,}])$" ignoreCase="true" />
              <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                <add input="{REQUEST_URI}" pattern="^/umbraco/" negate="true" />
                <add input="{REQUEST_URI}" pattern="^/install/" negate="true" />
                <add input="{REQUEST_URI}" pattern="^/([0-9]+).aspx" negate="true" />
                <add input="{URL}" pattern="^.*\.(asp|aspx|axd|asmx|css|js|jpg|jpeg|png|gif|mp3|htm)$" negate="true" ignoreCase="true" />
                <add input="{URL}" pattern="/Base" negate="true" />
                <add input="{URL}" pattern="cdv=1" negate="true" />
              </conditions>
              <action type="Redirect" redirectType="Permanent" url="{R:1}/" />
            </rule>
    
  • Murray Roke 452 posts 839 karma points c-trib
    May 02, 2019 @ 08:01
    Murray Roke
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft