【发布时间】:2013-02-01 18:08:17
【问题描述】:
我正在使用在 IIS 7.5 中运行的 mvc4 应用程序,但我在设置的重写规则方面遇到了问题。以下是我在 web.config 中的部分。
<rewrite>
<rules>
<rule name="RewriteImage">
<match url="/myassets/([_0-9a-z-]+)/images/category/([_0-9]+)-([_0-9a-z-]+)-([0-9]+)" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/myassets/{R:1}/images/category/cat_{R:2}_{R:4}_{R:3}.jpg" />
</rule>
</rules>
</rewrite>
我想在上面的 url 中将图像重写到另一个路径。
我提供以下网址 https://localhost/myassets/en-uk/images/category/123456-5x10-1_my+image+description.jpg 并希望它重写为 https://localhost/myassets/en-uk/images/category/cat_123456_1_5x10.jpg 但它没有。
当我在 IIS 中对其进行测试时,一切正常,但通过浏览器,规则永远不会生效。我正在寻找有关我哪里出错的建议,因为这变得非常令人沮丧!
这是我唯一的规则,我尝试了一个简单的重定向规则,它将大写 URL 重定向到小写 URL,这很好。
我在 web.config 中注意到的一件事是,第一个 rewrite 标记在下面有一个蓝色波浪线,表示它是 system.webserver 的未识别部分。
应用程序正在集成模式下运行。
【问题讨论】:
-
你怎么知道规则永远不会生效?文件
https://localhost/myassets/en-uk/images/category/cat_123456_1_5x10.jpg存在吗? -
如果你删除
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />会怎样? -
如果我这样做也没关系
-
所以图片
https://localhost/myassets/en-uk/images/category/cat_123456_1_5x10.jpg存在,当您调用https://localhost/myassets/en-uk/images/category/123456-5x10-1_my+image+description.jpg时它不会显示它,对吧?反而看到了什么?如果您使用Failed Request Tracing tool 会怎样?
标签: iis asp.net-mvc-4 url-rewriting iis-7.5