【问题标题】:Update a URL Query string in IIS URL Rewrite in IIS更新 IIS 中的 URL 查询字符串 IIS 中的 URL 重写
【发布时间】:2020-09-04 08:31:43
【问题描述】:

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

所以我尝试像这样进行正则表达式

实际网址

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}

你能帮帮我吗?

【问题讨论】:

标签: regex iis iis-express url-rewrite-module


【解决方案1】:

对于不同的网站,重定向是比 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+

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-24
    • 1970-01-01
    • 2021-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多