IIS重写不适用于应用程序的根目录

时间:2013-05-28 09:39:41

标签: asp.net-mvc-4 iis-7 url-rewriting root

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

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

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

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

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

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

默认情况下,内置的添加尾部斜杠不适用于目录或文件名...如果要将其应用于目录(如上面的示例http(s):// srv / app),则表示修改规则并删除具有&#34;类型:不是目录&#34;的条件。别忘了申请...

快乐网址重写! :)