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

News
.NET 9 Now Available

DotNet 9 Has been rolled ou...

News
Black Friday 2024 - FREE Umbraco Forms licence!

How to claim your FREE Umbr...

Umbraco
How to deploy Umbraco using Web Deploy from Azu...

How to deploy Umbraco using...

Umbraco
How to deploy Umbraco using Web Deploy from Git...

This blog post shows how yo...

Umbraco
Umbraco Medium Security Vulnerabilities - 22nd...

Security patches now availa...

ADVERTISTING
Browse Umbraco Hosting

Umbraco Hosting Starting At $26/month