How to add a trailing slash in Umbraco 8

Explicitly adding a trailing slash to Umbraco 8 URL's, or removing the trailing slash, is an important step in avoiding duplicate content on your site. Duplicate content refers to having the same content on different domains or URL's. Avoiding this is important for the SEO of your web site. And here is how you can add a trailing slash in Umbraco 8.

Add trailing slash in Umbraco

To add a trailing slash to Umbraco URL's, you first need to edit your site's ~/Config/umbracoSettings.config file. Look up the key requestHandler, and add:

<addTrailingSlash>true</addTrailingSlash>

Next you open your web.config file, and you need to add some URL Rewrite Module rewrite rules. Look up:

<!--
<rewrite>
	<rules></rules>
</rewrite>
-->

Remove the comment markers and add between <rules></rules>:

<rule name="Add trailing slash in Umbraco URL" stopProcessing="true">
	<match url="(.*[^/])$" />
	<conditions>
		<add input="{REQUEST_URI}" negate="true" pattern="^/(umbraco|DependencyHandler\.axd)" />
		<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>

It is important to exclude DependencyHandler.axd from rewriting (line 4), because HTTP requests fail if they contain /DependencyHandler.axd/.

Upload both files and restart your Umbraco web application. This is all that's needed to force a trailing slash in Umbraco.

Why is duplicate content bad?

Duplicate content confuses Google and forces the search engine to choose which of the identical pages it should rank in the top results. Regardless of who produced the content, there is a high possibility that the original page will not be the one chosen for the top search results.

Is an URL containing a trailing slash faster to load?

In the old days, some argued an URL with a trailing slash was faster to load, because it was treated as a directory by the web server and it didn't have to look for a file with that name. I guess that nowadays web servers (RAM and NVME SDD storage included) are so fast that there is hardly any performance gain.

But it's still important to choose an URL scheme: with or without trailing slash.