代码之家  ›  专栏  ›  技术社区  ›  Joe Lu

IIS URL重写重定向所有子目录

  •  1
  • Joe Lu  · 技术社区  · 7 年前

    我的网站有很多旧网页和目录没有使用。我没有删除它们,而是考虑使用重写规则将它们重定向到其父目录,

    例如,我有以下链接:

    • https://www.example.com/category/sub/1
    • https://www.example.com/category/sub2222/1/a
    • https://www.example.com/category/something/sub/3333

    我希望他们三个都重定向到 https://www.example.com/category .

    我尝试了下面的代码,但进入了一个无限循环。我想我必须指定规则do redirect,只有当它有子目录时:

    <rule name="Redirect-test" stopProcessing="true">
        <match url="category/(.*)" ignoreCase="true" />
        <action type="Redirect" url="https://www.example.com/category" />
    </rule>
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Joe Lu    7 年前

    好吧,也许我想得太多了,添加一个/(*)可以解决我的问题,我只是想知道这样的规则是否有任何缺陷

    <rule name="Redirect-test" stopProcessing="true">
        <match url="category/(.*)/(.*)" ignoreCase="true" />
        <action type="Redirect" url="https://www.example.com/category" />
    </rule>