在 IIS 中更新 URL 查询字符串 URL 在 IIS 中重写

Update a URL Query string in IIS URL Rewrite in IIS

我想在 IIS 中重写我的 URL 查询字符串,即更新我的 ip=0

所以我试着像这样正则表达式

实际URL

http://test.com/track/?ip=1&_=12345

预期结果

http://api.com/track/?ip=0&_=12345

我的正则表达式

http://test.com/([_0-9a-z-]+)/([?_0-9a-z]+)=([0-9]+)(.*)

http://api.com/{R:1}/{R:2}=0{R:4}

你能帮帮我吗?

对于不同的网站,重定向是比 Url 重写更好的方法。否则,重写适用于同一网站。
https://blogs.iis.net/owscott/url-rewrite-vs-redirect-what-s-the-difference
我们需要匹配查询字符串,然后我们可以将查询字符串的片段分配给新的动作。

ip=([0-9]+)&_=([0-9]+)

请参考以下截图。

网络配置。

<rewrite>
        <rules>
            <rule name="MyRule" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{QUERY_STRING}" pattern="ip=([0-9]+)&amp;_=([0-9]+)" />
                </conditions>
                <action type="Redirect" url="http://localhost/track?ip=0&amp;_={C:2}" appendQueryString="false" />
            </rule>
        </rules>
    </rewrite>

这里有一个相关的讨论。
https://forums.iis.net/t/1238891.aspx?Url+Rewrite+with+multiple+querystring+