How to remove trailing slash in Umbraco 8

By default Umbraco 8 will add a trailing slash to your URLs, for example

It is really easy to disable this behaviour and remove the trailing slash from the URLs.

Simply edit your umbracoSettings.config file which can be found in the config folder, then add the following line before the </requestHandler> tag.


This will tell Umbraco to stop adding the trailing slash to all your URLs, if the changes are not reflected straight away, be sure you recycle your Application Pool.

There are more options available for the requestHandler, you can find the full list here in the Umbraco Documentation.
Thanks to Warren on Twitter who reminded me of this page šŸ‘.

If you make this change on an active website with pre-existing content, then you will want to add a rewrite rule to take your users (and search bots) to the new URL with a 301 redirect.

To do this simply add the following rewrite to your Web.Config after the <rules> tag:

<ruleĀ name="RedirectTrailingSlash"Ā stopProcessing="true">
<match url="(.*?)/+$" />
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{REQUEST_METHOD}" pattern="^PUT$" negate="true" />
<add input="{REQUEST_METHOD}" pattern="^DELETE$" negate="true" />
<add input="{REQUEST_METHOD}" pattern="^PATCH$" negate="true" />
<add input="{REQUEST_URI}" pattern="^/umbraco/" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<action type="Redirect" redirectType="Permanent" url="{R:1}" />

Thanks to Ronald on Slack for providing an updated rewrite rule, this one skips POST, PUT, DELETE, PATCH as this would remove the body data, and excludes the Umbraco folder so that the previews continue to work correctly.

Comments (0)
Leave a Comment

Your comment

Contact Info