如果您只想匹配URL,並且只有一個問號太多,就可以使用重寫規則來做到這一點,就像您的示例一樣。如果你想匹配太多的問號,我認爲你需要爲鏈接的文章中詳細恢復到custom rewrite provider無限數量的
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Clean extra question mark from query string" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{QUERY_STRING}" pattern="^(.+?)(\?(.+))*$" />
</conditions>
<action type="Rewrite" url="/{URL}?{C:1}&{C:3}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
:然後,您可以使用此規則。您可能最終得到如下結果:
<rule name="Clean extra question mark from query string" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{QUERY_STRING}" pattern="^$" negate="true" />
</conditions>
<action type="Rewrite" url="/{URL}?{ReplaceProvider:{QUERY_STRING}}" appendQueryString="false" />
</rule>