【问题标题】:IIS Redirect not working without trailing slashIIS 重定向在没有斜杠的情况下无法正常工作
【发布时间】:2016-12-06 19:24:28
【问题描述】:

我有一个正在停用的网络应用程序,我正在尝试将所有对旧应用程序的请求重定向到特定页面(其中显示了一个替换链接和一条建议用户更新其书签的消息)。

我已经使用以下问题的答案在 web.config 中设置了 HTTP 重定向:ASP.NET httpRedirect : redirect all pages except one 并且它可以工作,除非用户输入站点根文件夹的 URL 省略了尾部斜杠,在这种情况下它转到树上的下一个目录,例如:

原站点根目录:[domain]/foo/bar/

[domain]/foo/bar/specificpage.aspx 重定向到[domain]/foo/bar/Default.aspx(确定)

[domain]/foo/bar/ 重定向到[domain]/foo/bar/Default.aspx(确定)

[domain]/foo/bar 重定向到 [domain]/foo/Default.aspx(不正常)

这是相关的 web.config:

<system.webServer>
    <httpRedirect enabled="true" destination="~/Default.aspx" httpResponseStatus="Permanent">
      <add wildcard="/" destination="Default.aspx" />
    </httpRedirect>
  </system.webServer>
  <location path="Default.aspx">
    <system.webServer>
      <httpRedirect enabled="false" />
    </system.webServer>
  </location>

当用户转到[domain]/foo/bar时,我怎样才能让它工作?

【问题讨论】:

    标签: asp.net iis web-config http-redirect


    【解决方案1】:

    为了记录,我通过将重定向 URL 设置为文件的绝对路径来解决此问题,包括站点根目录所在的虚拟目录:

    <system.webServer>
        <httpRedirect enabled="true" destination="/foo/bar/Default.aspx" httpResponseStatus="Permanent" exactDestination="true">
          <add wildcard="/" destination="Default.aspx" />
        </httpRedirect>
      </system.webServer>
      <location path="Default.aspx">
        <system.webServer>
          <httpRedirect enabled="false" />
        </system.webServer>
      </location>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-27
      • 2020-05-12
      • 2011-12-22
      • 2014-10-04
      • 2019-08-01
      • 1970-01-01
      相关资源
      最近更新 更多