我有这个重写规则:
<rule name="rentals by proptype+state+city+street test" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{UNENCODED_URL}" pattern="^/([a-zA-Z0-9\-+]+)/rent/province/([a-zA-Z\-+]+)/street/([a-zA-Z0-9%\-+]+)/([0-9a-zA-Z%\-+']+)$" />
</conditions>
<action type="Rewrite" url="search_new.aspx?proptype={C:1}&province={C:2}&city={C:3}&street={C:4}" appendQueryString="true" />
</rule>
我也试过:
<rule name="rentals by proptype+state+city+street test" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{UNENCODED_URL}" pattern="^/([a-zA-Z0-9\-+]+)/rent/province/([a-zA-Z\-+]+)/street/([a-zA-Z0-9%\-+]+)/([0-9a-zA-Z%\-+']+)$" />
<add input="{QUERY_STRING}" pattern=".*" />
</conditions>
<action type="Rewrite" url="search_new.aspx?proptype={C:1}&province={C:2}&city={C:3}&street={C:4}" appendQueryString="true" />
</rule>
此 URL 有效:http
://www.example.com/apartment/rent/province/texas/street/houston/mystreet
但是当我添加查询字符串参数时,URL 会抛出 404:http ://www.example.com /公寓/租金/省/德克萨斯/街道/休斯顿/mystreet?rooms=3&pricemin=2500
我已经在这里检查过:
IIS URL Rewrite not working with query string
https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference
https:// msdn.microsoft.com/en-us/library/ms972974.aspx
看来我必须使用QUERY_STRING
服务器变量。我实际上只是想附加查询字符串参数,而不必为每个参数编写特殊的映射。我以为我可以通过该appendQueryString="true"
属性解决此问题,但这显然行不通。
如何确保我的重写规则也适用于查询字符串参数?