0

We have ASP.NET application and set in web.config:

<rewrite>
  <rules>
    <rule name="RemoveTrailingSlashRule1" stopProcessing="true">
      <match url="(.*)/$" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="{R:1}" />
    </rule>
  </rules>
</rewrite>

But, the trailing slash is still there.

Also, I've tried to use the code in Global.asax.cs file:

protected void Application_BeginRequest(Object sender, EventArgs e)
{
    if (HttpContext.Current.Request.Url.ToString().Contains("http://concert.local/elki/"))
    {
        HttpContext.Current.Response.Status = "301 Moved Permanently";
        HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().Replace("http://concert.local/elki/", "http://concert.local/elki"));
    }
}

But, it doesn't work as well.

The specific is "elki" is subfolder in the project and has its own web.config file that looks as following:

<configuration>
  <system.webServer>
    <defaultDocument>
      <files>
        <add value="Sections.aspx" />
      </files>
    </defaultDocument>
    <httpRedirect enabled="true" destination="/elki" httpResponseStatus="Permanent" />
  </system.webServer>
</configuration>

How to make it work, that is remove trailing slash?

tesicg
  • 3,971
  • 16
  • 62
  • 121

1 Answers1

0

try removing it from the web.config ?

    <rewrite>
        <rules>
            <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>
        </rules>
    </rewrite>
Asim
  • 33
  • 1
  • 6