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