【问题标题】:IIS Rewrite does not work for the root of an applicationIIS 重写不适用于应用程序的根目录
【发布时间】:2013-05-28 09:39:41
【问题描述】:
使用 IIS7,URL Rewrite 2 在服务器 SRV 上有一个 MVC4 应用程序 APP。应该进行以下重写。
http://SRV/APP into http://SRV/APP/
我尝试创建 AddTrailingSlash 规则。但是,它不适用于应用程序的根。它确实适用于根目录下的目录,因此完成以下重写
http://SRV/APP/pipapo into http://SRV/APP/pipapo/
必须做什么才能使重写也适用于根?
【问题讨论】:
标签:
asp.net-mvc-4
iis-7
url-rewriting
root
【解决方案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>
【解决方案2】:
默认情况下,内置的添加斜杠不适用于目录或文件名...如果您希望它适用于目录(如上面的示例 http(s)://srv/app),您有修改规则并删除具有“类型:不是目录”的条件。不要忘记申请...
快乐的 URL 重写! :)