3

使用 IIS7,URL Rewrite 2 在服务器 SRV 上有一个 MVC4 应用程序 APP。应该发生以下重写。

http://SRV/APP into http://SRV/APP/

我尝试创建 AddTrailingSlash 规则。但是,它不适用于应用程序的根。它确实适用于根目录下的目录,因此完成了以下重写

http://SRV/APP/pipapo into http://SRV/APP/pipapo/

必须做什么才能使重写也适用于根?

4

2 回答 2

1

以下规则似乎对我有用:

<!--Add trailing slash to root non-file url-->
<rule name="Add trailing slash" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll">
        <!--Match uri's missing trailing slash-->
        <add input="{PATH_INFO}" pattern="(.*[^/])$" />
        <!--Ignore any uri containing a period (probably a better way to do this but IsFile was not behaving as expected for me)-->
        <add input="{PATH_INFO}" pattern="(.*?)\.(.*?)" negate="true"/>
    </conditions>
    <action type="Redirect" redirectType="Permanent" url="{PATH_INFO}/" />
</rule>
于 2013-10-22T16:21:26.023 回答
0

By default, the built in add trailing slash does not apply to directories or filenames... If you want it to apply to directories (like in the above example http(s)://srv/app), you have to modify the rule and delete the Condition that has "Type: Is Not a Directory". Don't forget to apply...

Happy URL Rewriting! :)

于 2014-03-25T21:31:49.570 回答