2017-10-11 170 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>