KNOWLEDGE BASE

Remove trailing slash from URL in Umbraco


A common issue with Umbraco is that front end URL's are available both with and without the trailing slash i.e.

mysite.com/testpage

mysite.com/testpage/

Although they are the same page, Google will see this as duplicate content and derank accordingly - what we need it a way to force Umbraco to remove the trailing slash.

There is a setting in the UmbracoSettings.Config file to add a trailing slash:

<requestHandler>
    <!-- this will add a trailing slash (/) to urls when in directory url mode -->
    <addTrailingSlash>true</addTrailingSlash>
</requestHandler>

But this does not really work for us in this situation - you can still access both url's (particularly in a multi domain site as was in my case)

The trick is to use the URL redirect rule shown below.
<rule name="Remove trailing 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>                                    

Need an Umbraco Master?

Here at Simon Antony, we have an in house certified Umbraco Grand Master available for hire. Got a problem with your site, need architecture advice, give us a call to speak to Simon directly and see how we can help

Contact Simon Today!