IIS 重定向在没有尾部斜线的情况下无法工作
IIS Redirect not working without trailing slash
我有一个正在停用的 Web 应用程序,我正在尝试将对旧应用程序的所有请求重定向到特定页面(显示 link 替换和一条消息,建议用户更新他们的书签)。
我已经使用这个问题的答案在 web.config 中设置了 HTTP 重定向: 并且除了用户输入站点的 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
时我如何让它工作?
郑重声明,我通过将重定向 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>
我有一个正在停用的 Web 应用程序,我正在尝试将对旧应用程序的所有请求重定向到特定页面(显示 link 替换和一条消息,建议用户更新他们的书签)。
我已经使用这个问题的答案在 web.config 中设置了 HTTP 重定向: 并且除了用户输入站点的 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
时我如何让它工作?
郑重声明,我通过将重定向 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>