A big part of building a successful website is optimizing and tweaking your site so it ranks well in search engines. One of Google's ranking factors is having a unique URL per page on your website. In Google's opinion, this URL www.website.com/page/and this URL www.website.com/page will count as two different URLs. Even though the URLs point to the same page, having a / at the end of one of the URLs can means that your page gets indexed twice! If this happens a lot on your site, your pages may be penalized in search ranking 😢.

SEO wise Google doesn't care if all your page URLs end with a trailing slash or without one. All Google really cares about is that you pick one. Technically, there is a slight difference between the two, however, as we work with Umbraco which is built upon virtual pages, the difference is less important than it would be in a normal static HTML site hosted in virtual. I feel it is still that important to understand the differences, so let us walk through some examples:

If you are building a website using folders and files, anything with a / at the end is meant to signify a directory. IIS, by default IIS will add the / if a directory exists and the request has omitted it, as mentioned here. Take this example www.website.com/parent/index.html

  • Segment relative to /parent/ = 'www.website.com/parent/index.html'

  • Segment relative to /parent = 'www.website.com/parent.html'

Having a trailing slash at the end of a URL can mean that the directory IIS checks can be different to what you expect. I've seen this confuse a few clients over the years, www.website.com/redirect goes to one page and www.websitecom/redirect/ has been accidentally configured to go to another web page!

When we work with a CMS like Umbraco, this issue is less important. For one Umbraco will generate most of the URLs will map to virtual pages rather than a physical file in a webroot.

Obviously, we will not want to manually check for a /, we will need a rule. My personal preference is to create a rule that removes the trailing/ from all URLs. based on my Google research, this way seems to be a lot more popular than adding a trailing /, however, it's up to you.

How Do I Remove The Trailing Slash?

As mentioned, we need a rule to enforce this policy. We can create a redirect rule to do this. There are a few different ways of creating re-direct rules in Umbraco. My recommendation would be to use the IIS UrlRewite tool. If you want to find out a little bit more about the best way to do redirects in Umbraco, you can read a more detailed case study here.

From this point forward I'm going to assume that you will be using UrlRewrite.

This rule tells the rewrite module to remove the trailing slash from the URL (if there is one) and then set the HTTP status to a 301 permanent redirect. This will rule now make your page sparkle with SEO goodness ✨✨✨. Happy Coding 🤘