Copied to clipboard

Flag this post as spam?

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


  • Dan Evans 629 posts 1016 karma points
    Aug 26, 2015 @ 21:15
    Dan Evans
    1

    Trailing slash / no slash - SEO

    Google recommends that there should be a unique URL for each page or if not then a 301 redirect or rel="canonical" be used.

    However Umbraco will serve the same page up on URLs with and without a trailing slash.

    e.g.

    www.mysite.com/about-us is the same as www.mysite.com/about-us/

    There is a setting which will add the slash to all URLs generated by Umbraco but does not stop access via the page without the /.

    The documentation advises how to create a canonical URL for a page:

    https://our.umbraco.org/wiki/reference/code-snippets/razor-snippets/canonicalurl/

    This however will create 2 different canonical URLs depending on whether the user is on the page with the / or without.

    So I'm wondering:

    1. Is there an easy solution to this.

    2. Why is this solution not part of the core when it's quite a fundamental SEO issue.

  • Robert Foster 459 posts 1820 karma points MVP 2x admin c-trib
    Aug 27, 2015 @ 03:36
    Robert Foster
    0

    Hi Dan, You can change the behaviour for the trailing slash by editing the /config/UmbracoSettings.config file - look for addTrailingSlash.

    Also, if you're looking at SEO with Umbraco, I highly recommend the SEOChecker package - it's a commercial package, 99 Euro - but I think you'll find it's a great investment.

    http://soetemansoftware.nl/seo-checker/features

    EDIT: I should have read your comment more thoroughly - of course you already found that setting - anyways, take a look at SEO Checker - it handles a lot of the SEO issues, and also has built-in redirection for old/broken links and a range of other issues.

  • mscommunities 40 posts 95 karma points
    Aug 27, 2015 @ 05:37
    mscommunities
    2

    Hi Dan, what you want to do is use the rewrite capabilities of the IIS Rewrite Module. Ruslan has made a great blog post on this: http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/#trailing-slash

    You can choose to either remove or add trailing slashes to all urls:

    Remove trailing slash to urls

    <rule name="Remove trailing slash" stopProcessing="true">
    <match url="(.*)/$" />
    <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Redirect" redirectType="Permanent" url="{R:1}" />
    </rule>
    

    Add trailing slash to urls

    <rule name="Add trailing slash" stopProcessing="true">
    <match url="(.*[^/])$" />
    <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Redirect" redirectType="Permanent" url="{R:1}/" />
    </rule>
    
  • Dan Evans 629 posts 1016 karma points
    Aug 27, 2015 @ 06:53
    Dan Evans
    0

    Thanks for the advice guys. I had found the rewrite module and SEO checker and will look at implementing them. We already use the URL Tracker.

    Can URLRewriting.config not be used?

    I guess my point is that I can see no reason why you would want to be able to access a page with and without a slash therefore why do we need to implement a workaround to stop it happening and is this not a bug in the addTrailingSlash config?

  • Robert Foster 459 posts 1820 karma points MVP 2x admin c-trib
    Aug 27, 2015 @ 07:00
    Robert Foster
    0

    Hi Dan, Yes, you could use the URLRewriting.config module - it's just an alternative to the IIS Rewrite Module, that's all; either solution could be used.

    If you think it's a valid issue, put it up on http://issues.umbraco.org - best way to get feedback on it with the Core team (you could also link the new issue here).

  • Daniel Bardi 927 posts 2562 karma points
    Aug 23, 2016 @ 17:19
    Daniel Bardi
    0

    I know I'm a bit late to the party, but here are UrlRewriting.config versions:

    Add Trailing Slash

    <add name="301Redirect_AddTrailingSlash"
      redirectMode="Permanent"
      redirect="Application"
      ignoreCase="true"
      rewriteUrlParameter="IncludeQueryStringForRewrite"
      virtualUrl="(.*[^/])$"
      destinationUrl="$1/" />
    

    Remove Trailing Slash

    <add name="301Redirect_RemoveTrailingSlash"
      redirectMode="Permanent"
      redirect="Application"
      ignoreCase="true"
      rewriteUrlParameter="IncludeQueryStringForRewrite"
      virtualUrl="(.*)/$"
      destinationUrl="$1" />
    

    Hope this helps someone. (NOTE: Use either one or the other; not both!)

  • Sagar 74 posts 275 karma points
    May 06, 2017 @ 05:22
    Sagar
    0

    unable to find "UrlRewriting.config"

  • Tom 34 posts 154 karma points
    Oct 03, 2017 @ 09:27
    Tom
    0

    This creates another problem since resources are not loaded if a trailing slash is added to its path (such as file.js/). Do you know of any workaround?

  • Dan Evans 629 posts 1016 karma points
    Aug 27, 2015 @ 07:07
    Dan Evans
    0

    Thanks Robert. Only problem is I can't find a UrlRewriting.net rule that does this!

    I will submit to the issue tracker.

  • Dan Evans 629 posts 1016 karma points
    Aug 27, 2015 @ 07:42
    Dan Evans
    1

    Submitted - http://issues.umbraco.org/issue/U4-7025

    There's actually even more ways to access a page:

    www.mysite.com/about-us www.mysite.com/about-us/ www.mysite.com/about-us.aspx www.mysite.com/1223 www.mysite.com/1223.aspx

    So 5 ways to get to a single page.

    Vote for it if you agree! It's in the recommendations:

    https://support.google.com/webmasters/answer/66359

  • David Armitage 505 posts 2073 karma points
    Jul 24, 2018 @ 05:46
    David Armitage
    0

    Great. Thanks for the help. Saved me some time figuring out writing the rewrite rule.

    Kind Regards

    David

  • David Armitage 505 posts 2073 karma points
    Jul 24, 2018 @ 06:13
    David Armitage
    0

    Hi Peeps,

    I added a re-write rule and this worked for all my pages but this then introduced a bug loading Umbraco's back-end. It simple didn't load.

    I tested removing the re-write rule again and the back-end was fine so its defo related.

    Any ideas to how to get this re-write rule working but not effecting the back-end login.

    Umbraco version 7.7.9 assembly: 1.0.6596.21099

    Thanks in advanced!

    Kind Regards

    David

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Jul 24, 2018 @ 06:18
    Dave Woestenborghs
    2

    Hi David,

    You probably need to add this rule before your rewrite rule that changes the url.

    <rule name="WhiteList" stopProcessing="true">
              <match url="(.*)" />
              <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
                <add input="{URL}" pattern="^.*/(umbraco|umbraco_client|client|install|api|App_Plugins)/" ignoreCase="true" />
                <add input="{HTTP_HOST}" pattern=".*localhost.*" ignoreCase="true" />
              </conditions>
              <action type="None" />
            </rule>
    

    This will stop the rewrite from happening on umbraco related urls.

    Dave

  • David Armitage 505 posts 2073 karma points
    Jul 24, 2018 @ 06:23
    David Armitage
    0

    Absolute legend! That worked a treat.

    Thanks for your help.

    Kind Regards

    David

Please Sign in or register to post replies

Write your reply to:

Draft