2011-09-02 87 views
0

我有附加的重定向和重写规则。基本上,www.foo.com/vehicles/vehicle-detail.aspx?stockno=123456被重写为www.foo.com/123456。这符合我所制定的规则的预期。现在,如果我尝试浏览不存在的页面(即www.foo.com/test.aspx),则重写规则有资格,IIS尝试将请求转发到www.foo.com/vehicles/vehicle-detail。 aspx(没有查询字符串)。在vehicle-detail.aspx页面中,如果querystring中没有有效的stockno,那么我有代码重定向到主页,所以这就是发生了什么。我不知道如何纠正规则,以免条件不符合规定。我附加了失败请求跟踪的规则和屏幕截图,使我能够查看请求/重写规则。URL重写模块IIS7不正确处理重写规则

<rule name="Redirect StockNo" enabled="true" stopProcessing="true"> 
<match url="^Vehicles/Vehicle-Detail\.aspx$" /> 
<conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
    <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> 
    <add input="{QUERY_STRING}" pattern="^stockno=([^=&amp;]+)$" /> 
</conditions> 
<action type="Redirect" url="{C:1}" appendQueryString="false" /> 

<rule name="Rewrite StockNo" enabled="true" stopProcessing="true"> 
<match url="^([^/]+)/?$" /> 
<conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
</conditions> 
<action type="Rewrite" url="Vehicles/Vehicle-Detail.aspx?stockno={R:1}" /> 

enter image description here

enter image description here

enter image description here

回答

0

你需要的是友善模式更独特的东西。如果你知道它总是会是数字,你可以有:

<match url="^([\d]+)/?$" /> 

这只会匹配www.foo.com/{digits}带有可选尾随斜线。

另一种选择是使url类似于www.foo.com/s/{stockno}/。用/ s /你有一些你可以自信地匹配的独特的东西。 S只是一个简短的例子,所以你可以使用你想要的东西。

+0

非常感谢。你的回应让我想到如何配置我需要的东西。谢谢!! – obautista