title: IIS - Remove trailing slash when directory
body: <p>I want to remove trailing slashes from all requests from "/" to "", even when it's a directory. For instance:</p>
  
  <ul>
  <li>Folder: <em><a href="http://bleh.local/sign-in/" rel="nofollow noreferrer">http://bleh.local/sign-in/</a></em></li>
  <li>File to be served: <em><a href="http://bleh.local/sign-in/index.html" rel="nofollow noreferrer">http://bleh.local/sign-in/index.html</a></em></li>
  <li>Default document: <em>index.html</em></li>
  </ul>
  
  <p>I would like to redirect it to "<a href="http://bleh.local/sign-in" rel="nofollow noreferrer">http://bleh.local/sign-in</a>"</p>
  
  <ul>
  <li>Expected behavior: <em>/sign-in/</em> redirected to <em>/sign-in</em></li>
  <li>Actual behavior: <em>/sign-in</em> redirected to <em>/sign-in/</em></li>
  </ul>
  
  <p>Web.config:</p>
  
  <pre><code>&lt;rule name="RemoveTrailingSlashRule1" enabled="true" stopProcessing="true"&gt;
        &lt;match url="(.*)/$" /&gt;
        &lt;conditions&gt;
          &lt;add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /&gt;
        &lt;/conditions&gt;
        &lt;action type="Redirect" url="{R:1}" /&gt;
  &lt;/rule&gt;
  </code></pre>
  
  <p>applicationHost.config:</p>
  
  <pre><code>&lt;sectionGroup name="rewrite"&gt;
      &lt;section name="globalRules" overrideModeDefault="Allow" allowDefinition="AppHostOnly" /&gt;
      &lt;section name="rules" overrideModeDefault="Allow" /&gt;
      &lt;section name="outboundRules" overrideModeDefault="Allow" /&gt;
      &lt;section name="providers" overrideModeDefault="Allow" /&gt;
      &lt;section name="rewriteMaps" overrideModeDefault="Allow" /&gt;
      &lt;section name="allowedServerVariables" overrideModeDefault="Allow" /&gt;
  &lt;/sectionGroup&gt;
  </code></pre>
  
  <p>With this setup, I get infinite redirects because I removed this instruction from the original setup:</p>
  
  <pre><code>&lt;conditions&gt;
      &lt;add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /&gt;
  &lt;/conditions&gt;
  </code></pre>
  
  <p>I think my problems come from this: <a href="https://support.microsoft.com/en-ca/help/298408/iis-generates-courtesy-redirect-when-folder-without-trailing-slash-is" rel="nofollow noreferrer">https://support.microsoft.com/en-ca/help/298408/iis-generates-courtesy-redirect-when-folder-without-trailing-slash-is</a></p>
  
  <p>Any ideas?</p>
  
  <p>Note: <a href="https://stackoverflow.com/questions/47274704/how-can-i-configure-iis-to-serve-directories-without-trailing-slashes-and-always?rq=1">How can I configure IIS to serve directories without trailing slashes and always serve relative to root path?</a> is not solving my problem. The backslashes are added consistently.</p>