Category

Umbraco

By default Umbraco 8 will add a trailing slash to your URLs.

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.

<addTrailingSlash>false</addTrailingSlash>

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="(.*?)/+$" />
  <conditions>
  <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" />
  </conditions>
  <action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>

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

Post a comment

Fields marked with an * (asterisk) are required


Recent Posts

Tips & Tricks
How to use Cloudflare Workers and Transform Rul...

This post explains how to m...

News
UmbHost Limited is now a Silver Umbraco Partner

We are now officially a Sil...

Umbraco
How to pass a Content Security Nonce (CSP) to G...

How to use a CSP nonce with...

News
UmbCheckout 1.0.0 & UmbCheckout.StarterKit.Stri...

The stable version of UmbCh...

News
Voting is now open for the Green Business of th...

We've been shortlisted! - P...

ADVERTISTING
Browse Umbraco Hosting

Umbraco Hosting Starting At $26/month