Redirect IIS 7重写规则-基于查询字符串的存在重定向

Redirect IIS 7重写规则-基于查询字符串的存在重定向,redirect,iis-7,web-config,Redirect,Iis 7,Web Config,是否可以根据最初请求的URL中存在的查询字符串使用web.config重定向?我不确定条件中包括什么。我是web.config中重写/重定向规则的初学者,希望了解更多有关语法、参数等的信息 我正在尝试这样做: <rewrite> <rules> <rule name="Restricted Folder with Querystring" stopProcessing="true"> <match url="^test folder/(.*)" ign

是否可以根据最初请求的URL中存在的查询字符串使用web.config重定向?我不确定条件中包括什么。我是web.config中重写/重定向规则的初学者,希望了解更多有关语法、参数等的信息

我正在尝试这样做:

<rewrite>
<rules>

<rule name="Restricted Folder with Querystring" stopProcessing="true">
<match url="^test folder/(.*)" ignoreCase="false" />

    <conditions>
    <!--redirect to a certain page if a certain querystring is present -->
    </conditions>             
<action type="Redirect" redirectType="Permanent" url="/test folder/{R:1}" />
</rule>

<rule name="Restricted Folder without Querystring" stopProcessing="true">
<match url="^test folder/(.*)" ignoreCase="false" />              
    <conditions>
    <!--redirect to another page if querystring is not present -->
    </conditions>             
<action type="Redirect" redirectType="Permanent" url="https://www.whatever.com/page.asp?url={R:1}" />
</rule>

</rules>
</rewrite>
<rules>
    <rule name="Restricted Folder Gimbal" stopProcessing="false">
      <match url="(.*)"  ignoreCase="true" />
      <conditions>
         <add input="{QUERY_STRING}" pattern="^whateverpattern"  />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="http://www.whatever.com/file.html" />
    </rule>     
  </rules>

我在地图上找到了答案。在web.config的“重写”部分中,无论您想从哪个文件夹执行重定向,它都会如下所示:

<rewrite>
<rules>

<rule name="Restricted Folder with Querystring" stopProcessing="true">
<match url="^test folder/(.*)" ignoreCase="false" />

    <conditions>
    <!--redirect to a certain page if a certain querystring is present -->
    </conditions>             
<action type="Redirect" redirectType="Permanent" url="/test folder/{R:1}" />
</rule>

<rule name="Restricted Folder without Querystring" stopProcessing="true">
<match url="^test folder/(.*)" ignoreCase="false" />              
    <conditions>
    <!--redirect to another page if querystring is not present -->
    </conditions>             
<action type="Redirect" redirectType="Permanent" url="https://www.whatever.com/page.asp?url={R:1}" />
</rule>

</rules>
</rewrite>
<rules>
    <rule name="Restricted Folder Gimbal" stopProcessing="false">
      <match url="(.*)"  ignoreCase="true" />
      <conditions>
         <add input="{QUERY_STRING}" pattern="^whateverpattern"  />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="http://www.whatever.com/file.html" />
    </rule>     
  </rules>


是一个非常方便的参考,不幸的是,我花了比预期更长的时间才找到。

deeholzman,我相信对于您的条件-添加输入示例,您希望使用“模式”而不是“匹配类型”。例:



您应该根据@emailstudioadam注释更改代码。
<add input="{QUERY_STRING}" pattern="^whateverpattern" negate="true" />