2017-10-11 90 views
1

我的网站有很多旧页面和目录未被使用。而不是删除它们,我正在考虑使用重写规则将其重定向到它的父目录,IIS URL重写重定向所有子目录

例如,我有以下链接:

  • 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

我试了下面的代码,但进入了一个无限循环。猜猜我必须指定规则做重定向,只有当它有一个子目录:

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

回答

0

好吧,也许我得太多了这一点,添加/(.*)将解决我的问题,我只是想知道,如果这种规则中有任何缺陷

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