我已经建立了一些示例,第一个是使用Condition
元素来捕获我需要的其余URL的长手版本。这有效,但我不明白为什么以下更简洁的例子不会起作用。
<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>
然后我有一个小改动这个例子,但然后打破并且不匹配我的测试网址。
请参阅Match Url
d{4}\/)
并参见参考Action Url
{R:2}/videogallery
<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
答案 0 :(得分: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>