首页 > 解决方案 > IIS Web.config 将一个子文件夹重定向到另一个

问题描述

我的 web.config 文件中有以下路由规则,但它不适用于以下路由:

www.domain.com/folder/new-sub/page

www.domain.com/folder-new/new-sub/page

如我所愿。任何人都可以帮助我更正以下规则,以便它适用于上述用例吗?

<rule name="Redirecting folder to folder-new" stopProcessing="true">
                <match url="^folder/$" />
                <action type="Redirect" redirectType="Permanent" url="/folder-new" />
            </rule>

编辑-更具体地说...我不想硬编码新子/页面...我想要“文件夹”子目录中的任何内容到“新文件夹”子目录

标签: asp.netwebiisweb-config

解决方案


这是我修复它的方法:

<rule name="Redirecting folder to new-folder" stopProcessing="true">
                <match url="^/?folder/(.*)" />
                <action type="Redirect" redirectType="Permanent" url="/new-folder/{R:1}" />
            </rule>

推荐阅读