我有這樣的重寫規則URL重寫:正則表達式與可選的查詢字符串參數
<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/apartment/rent/province/texas/street/houston/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"
屬性解決這個問題,但這顯然不起作用。
我怎樣才能確保我的重寫規則也適用於查詢字符串參數?
Jup,就是這樣。謝謝,將在23小時內獎勵賞金:-) – Flo
@Flo歡迎您:) –