【发布时间】:2018-08-24 19:03:00
【问题描述】:
我想从“/”到“”的所有请求中删除尾部斜杠,即使它是一个目录。例如:
- 文件夹:http://bleh.local/sign-in/
- 要送达的文件:http://bleh.local/sign-in/index.html
- 默认文档:index.html
我想将其重定向到“http://bleh.local/sign-in”
- 预期行为:/sign-in/ 重定向到 /sign-in
- 实际行为:/sign-in 重定向到 /sign-in/
Web.config:
<rule name="RemoveTrailingSlashRule1" enabled="true" stopProcessing="true">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}" />
</rule>
applicationHost.config:
<sectionGroup name="rewrite">
<section name="globalRules" overrideModeDefault="Allow" allowDefinition="AppHostOnly" />
<section name="rules" overrideModeDefault="Allow" />
<section name="outboundRules" overrideModeDefault="Allow" />
<section name="providers" overrideModeDefault="Allow" />
<section name="rewriteMaps" overrideModeDefault="Allow" />
<section name="allowedServerVariables" overrideModeDefault="Allow" />
</sectionGroup>
使用此设置,我会获得无限重定向,因为我从原始设置中删除了此指令:
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
有什么想法吗?
注意:How can I configure IIS to serve directories without trailing slashes and always serve relative to root path? 没有解决我的问题。反斜杠的添加是一致的。
【问题讨论】:
-
从 1 天开始进入同样的问题。不幸的是,互联网上没有任何帮助。
标签: html redirect iis web-config