简体   繁体   English

在IIS重写中提取参数-我在哪里出错?

[英]Extracting arguments in IIS rewrite - where am I going wrong?

How can I redirect '/path?foo=abc&bar=def' to '/path/abc/def'? 如何将'/ path?foo = abc&bar = def'重定向到'/ path / abc / def'?

I've tried the following: 我尝试了以下方法:

<rule name="My rule" stopProcessing="false">
    <match url="^path" />
    <conditions>
        <add input="{QUERY_STRING}" pattern="foo=/[^&amp;]*/" />
        <add input="{QUERY_STRING}" pattern="bar=(.*)" />
    </conditions>
    <action type="Redirect" url="/path/{C:0}/{C:1}" appendQueryString="false" />
</rule>

But this doesn't even process my match. 但这甚至不处理我的比赛。 Where am I going wrong? 我要去哪里错了?

I don't have access to a computer to verify this, but I think the following could simplify: 我无权使用计算机进行验证,但是我认为可以简化以下内容:

<rule name="Redirect old FAQ view" stopProcessing="false">
    <match url="^path.*" />
    <conditions>
        <add input="{QUERY_STRING}" pattern="^foo=([^&]*).*?bar=(.*)" />
    </conditions>
    <action type="Redirect" url="/path/{C:0}/{C:1}" appendQueryString="false" />
</rule>

You don't need the second input line as you can use multiple capturing groups in one. 您不需要第二个输入行,因为您可以在一个输入中使用多个捕获组。 I'm not sure if the whole line will come back as a match or not so you may need to adjust to {C:1}/{C:2} . 我不确定整行是否会匹配,因此您可能需要调整为{C:1}/{C:2} Finally, I'm not sure if the match url was problematic. 最后,我不确定匹配网址是否有问题。 It would contain the query string as well, so that may have been causing it to miss. 它也将包含查询字符串,因此可能导致其丢失。 Look here for more details on the various components of the URL rewrite process. 在此处查找有关URL重写过程的各个组成部分的更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM