【问题标题】:IIS rewrite rule not passing query parameterIIS 重写规则未传递查询参数
【发布时间】:2016-04-10 07:25:06
【问题描述】:

我想我正在尝试做一些应该简单的事情。我想要一个重写规则,它接受来自许多域的任何传入请求,并将其重写为 /redirect.aspx?src=original URL

这就是我所拥有的

<rewrite>
  <rules>
    <rule name="SimpleURL" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{URL}" negate="true" pattern="\.aspx$"/>
      </conditions>
      <action type="Redirect" url="/Redirect.aspx?src={R:0}" appendQueryString="true" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

除了传递的查询参数是 src= 没有任何值之外,它可以工作。

我进行了更改,现在它为查询参数传递了一个硬编码值

I made a change so it is now passing a value for the parameter. 


<rewrite>
  <rules>
    <rule name="SimpleURL" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{URL}" negate="true" pattern="\.aspx$"/>
        <add input="{QUERY_STRING}" pattern="src=(.*)" negate="true" />
      </conditions>
      <action type="Redirect" url="/Redirect.aspx?src=foobar" appendQueryString="true" redirectType="Found" />
    </rule>
  </rules>
</rewrite>

如果我将 foobar 替换为 {R:0},则不会传递任何值。在此处输入代码硬编码的foobar值被传递。

【问题讨论】:

    标签: iis url-rewriting


    【解决方案1】:

    您的规则看起来不错,并且在我的机器上运行良好,但是您使用的是永久重定向。您在测试时是否对规则进行了任何更改?尝试从隐身/私人模式浏览器测试它或测试不同的 URL。

    试试下面的规则:

    <rule name="SimpleURL" stopProcessing="true">
      <match url="(.*)" />
      <conditions trackAllCaptures="true">
        <add input="{URL}" negate="true" pattern="\.aspx$"/>
        <add input="{QUERY_STRING}" pattern="src=(.*)" negate="true" />
        <add input="{URL}" pattern="(.*)" />
      </conditions>
      <action type="Redirect" url="/Redirect.aspx?src={C:2}" appendQueryString="true" redirectType="Found" />
    </rule>
    

    【讨论】:

    • 我进行了更改,现在它正在为参数传递一个值
    • 我在原始答案中添加了一条规则。请看看它是否能解决您的问题。
    猜你喜欢
    • 2021-05-10
    • 2021-04-11
    • 1970-01-01
    • 2013-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-21
    • 2018-02-12
    相关资源
    最近更新 更多