How To Remove The Trailing Slash in Umbraco

A big part of building a successful website is optimizing and tweaking your site to work with Google in the best possible manner.  One of Google's ranking factors is having unique URLs for your web pages.

In Google's terms, this URL www.website.com/page/ and this URL www.website.com/page will count as two different URLs for the same bit of content and the Google spider may penalize your site because of it.

SEO wise Google doesn't care if you have all your URLS with a trailing slash or without one.  All Google really cares is that you pick one.

Technically, there is a slight difference between the two, however, as we work with Umbraco where your website is built upon virtual pages, the difference is less important than it would be in a normal static HTML site hosted in virtual.

First, 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.  As you can probably guess, as we work with virtual pages this isn't really a big deal.

I've also seen a few clients get confused when setting relative URLs up. If a directory exists, then in this URL www.website.com/parent/index.html

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

So having a trailing slash can mean that the relative directory path that IIS will look in can be different.  I've seen this confuse a few clients over the years.  Say www.website.com/redirect goes to one page and www.websitecom/redirect/ has been accidently configured to go to another web page!   

When we work with CMS systems though, these two things are a lot less important, for one Umbraco will generate most of the URLS so the difference is unimportant.

My personal preference would be to remove the trailing / and from my Google research, this way seems to be a lot more popular than adding a trailing / but it's up to you.

How Do I Remove The Trailing Slash?

I've written a few posts now about the different ways of doing re-directs in Umbraco.  My recommendation would be to use the inbuilt UrlRewite tool that comes with IIS.  If you want to find out a little bit more about that discussion you can here.  From this point forward I'm going to assume that you will be using UrlRewrite.

<rewrite>
  <rules>
    <rule name="Remove 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>
    
  </rules>
</rewrite>

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. 

submit to reddit

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

Back to top