【发布时间】:2015-08-27 05:39:14
【问题描述】:
我正在使用两个简单的规则来实现友好的url。
他们正在寻找,但我看不到图像并且有一个错误
ASP.NET 3.5 网站的友好网址
http://localhost/Test/Products/888/9999
错误
http://localhost/Test/Products/888/Images/Jellyfish.jpg加载失败 资源:服务器响应状态为 404(未找到)
规则
<rule name="t2" enabled="true">
<match url="^products/([0-9]+)/([0-9]+)" negate="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="products.aspx?p={R:1}&pc={R:2}" />
</rule>
<rule name="t1" enabled="true">
<match url="^product/([0-9]+)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="product.aspx?p={R:1}" />
</rule>
我看到 IIS 正在构建错误的图像路径,就像它说的那样
有什么线索吗?
【问题讨论】:
-
我不太明白。除了 url
http://localhost/Test/Products/888/9999之外,您是返回位置http://localhost/Test/Products/888/Images/Jellyfish.jpg的图像,还是您的 product.aspx 返回图像。你想获取的图片的真实网址是什么? -
@PeterHahndorf 网址
http://localhost/Test/Products/888/9999用于打开 Products.aspx。但不知何故,IIS 正在重写此页面内图像的路径。此页面有一个简单的``,无需重写规则即可正常工作。 -
因此图像的 src 是相对于页面的,浏览器将请求类似 `localhost/Test/Products/888/9999/images/jellyfish.jpg' 的内容,这将由您的重写规则获取。在 F12 浏览器工具中,检查图像的实际请求 url。您必须从规则中排除图像或使用非相对路径。
-
@PeterHahndorf 我该怎么做?
-
您可以在规则中添加
<conditions><add input="{REQUEST_URI}" pattern="\.jpg" negate="true" /></conditions>之类的条件,或者<conditions><add input="{REQUEST_URI}" matchType="IsFile" negate="true" /></conditions>您必须确保您的图像不符合规则。
标签: asp.net iis-7 friendly-url url-rewrite-module