Remove Trailing Slash From the URL

In your web.config, under the system.webServer, add


    <!--To always remove trailing slash from the URL-->
    <rule name="Remove trailing slash" stopProcessing="true">
      <match url="(.*)/$" />
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      <action type="Redirect" redirectType="Permanent" url="{R:1}" />


Some Gotchas

In your development environment, if you run your web site under Visual Studio Development Sever, you won't be able to see this feature working. You will need to configure your application to run under at least IIS Express.

When you deploy your web site and see that this feature is not working on your production server, it will be because you miss configured something. One of the common mistakes is having overrideModeDefault attribute set to Deny for rules under <sectionGroup name="rewrite"> inside your applicationHost.config file.

If you are on a shared hosting environment and you see that this feature is not working, ask your provider if they have given you the permission of configuring this part.


I know this is an old post, but Mihai's answer can make your applicatin vulnerable to open redirects attack

<action type="Redirect" redirectType="Permanent" url="{R:1}" />

This redirect URL can be used for an external redirect, so make sure you have other validations in place before this rule is evaluated or change the redirect to make it internal instead. If you really want to remove the trailing slash and keep it internal, you can change it to:

<action type="Redirect" redirectType="Permanent" url="/{R:1}" />