0

我们有 ASP.NET 应用程序并在 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>

但是,尾部斜线仍然存在。

另外,我尝试使用 Global.asax.cs 文件中的代码:

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"));
    }
}

但是,它也不起作用。

具体来说,“elki”是项目中的子文件夹,它有自己的 web.config 文件,如下所示:

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

如何使其工作,即删除斜杠?

4

1 回答 1

0

尝试从 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>
于 2013-10-30T03:42:19.483 回答