IIs重写规则将值附加到查询字符串

时间:2013-06-27 04:47:33

标签: c# asp.net iis-7 url-rewriting

我正在尝试整天在IIS中创建URL重写规则,但我的规则都不起作用..

我想重写url来转换这些类型的Url

http://localhost:2811/Search/S%2fqIMmjstZg%3d/VehicleDetails.aspxhttp://localhost:2811/Search/VehicleDetails.aspx?mid=S%2fqIMmjstZg%3d

http://localhost:2811/Search/yYut%2f%2fBrHa8%3d/VehicleDetails.aspx To http://localhost:2811/Search/VehicleDetails.aspx?mid=yYut%2f%2fBrHa8%3d

http://localhost:2811/Search/nNLApdJeWJI%3d/VehicleDetails.aspx To http://localhost:2811/Search/VehicleDetails.aspx?mid=nNLApdJeWJI%3d

以下重写规则

<rewrite>
        <rules>
            <rule name="QueryString">
                <match url="^Search/([_0-9a-z-%=\+\$]*)$/VehicleDetails.aspx" />
                <action type="Rewrite" url="Search/VehicleDetails.aspx?mid={R:1}" appendQueryString="true" />
            </rule>
        </rules>
    </rewrite>

但它没有用......请帮助!!!

1 个答案:

答案 0 :(得分:3)

你有错误的模式。我建议你关注:

/Search/([^/]*)/VehicleDetails.aspx$

现在解释(从结尾)

  1. /VehicleDetails.aspx$ - 静态文本,位于字符串的末尾
  2. ([^ /]) - 除“/”
  3. 之外的所有内容
  4. /搜索/ - 静态文本(你coluld尝试在乞讨中添加^但是要小心/之后)
  5. 您可以在IIS UI中测试您的表达式:enter image description here