【问题标题】:IIS Url Rewrite Match not working without ConditionIIS Url Rewrite Match 在没有条件的情况下无法正常工作
【发布时间】:2017-12-27 17:22:24
【问题描述】:

我已经建立了几个例子,第一个是使用Condition 元素来捕获我需要的其余网址的长手版本。这可行,但我不明白为什么以下更简洁的示例不起作用。

   <rule name="my-videos">
    <match url="(.*)(trips\/[\w-]+\/[\w-]+\/[\w-]+\/\d{4})" />
    <conditions>
      <add input="{URL}" pattern="my-videos(.*)" />
    </conditions>
    <action type="Redirect" url="{R:2}/videogallery{C:1}" redirectType="Permanent" />
   </rule>

然后我有一个小改动的示例,但随后中断并且与我的测试 url 不匹配。

Match Url结尾

d{4}\/)

参见参考Action Url

{R:2}/视频库
<rule name="my-videos">
    <match url="(.*)(trips\/[\w-]+\/[\w-]+\/[\w-]+\/\d{4}\/)" />
    <conditions>
      <add input="{URL}" pattern="my-videos(.*)" />
    </conditions>
    <action type="Redirect" url="{R:2}videogallery{C:1}" redirectType="Permanent" />
  </rule>

那么理想情况下是没有Condition 元素的组合最终版本

  <rule name="my-videos">
    <match url="(.*)(trips\/[\w-]+\/[\w-]+\/[\w-]+\/\d{4}\/)my-videos(.*)" />
    <action type="Redirect" url="{R:2}videogallery{R:3}" redirectType="Permanent" />
  </rule>

这里有一些示例测试应该将my-videos 替换为videogallery

请求:trips/my-adventures/asia/india/2018/my-videos

预期:trips/my-adventures/asia/india/2018/videogallery

请求:trips/my-adventures/asia/india/2018/my-videos?fullscreen=true

预期:trips/my-adventures/asia/india/2018/videogallery?fullscreen=true

请求:trips/my-adventures/asia/india/2018/my-videos/vines

预期:trips/my-adventures/asia/india/2018/videogallery/vines

请求:trips/my-adventures/asia/india/2018/my-videos/vines?fullscreen=true

预期:trips/my-adventures/asia/india/2018/videogallery/vines?fullscreen=true

【问题讨论】:

  • 您能否在您的示例中添加您希望重定向到的网址。它将帮助我为您建立更好的规则
  • 全部设置@victor

标签: .net regex xml iis


【解决方案1】:

这条规则正是你所需要的:

<rule name="my-videos" stopProcessing="true">
    <match url="(.*trips\/[\w-]+\/[\w-]+\/[\w-]+\/\d{4}\/)my-videos(.*)" />
    <action type="Redirect" url="{R:1}videogallery{R:2}" />
</rule>     

【讨论】:

  • 看来我的版本的问题是比赛中最初的 .* ,如果以后有人读到这个来分析它为什么不起作用。我实际上可以在没有 stopProcessing="true" 的情况下以 Victor 为例,它仍然有效
  • 是的,stopProcessing 不是必需的。但是恕我直言,为了更好地理解和支持庞大的规则列表,最好拥有它,因为如果stopProcessing="true",则意味着不会再处理后续规则,并且该规则生成的URL将传递给IIS 请求管道。
猜你喜欢
  • 2016-12-06
  • 1970-01-01
  • 2013-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多