2017-11-10 359 views
0

我在IIS 10.0上使用URL重寫,並在服務器級別(applicationHost.config)配置了以下規則。我已經在我的web.config中嘗試過,但也無濟於事。URL重寫無法在IIS 10.0上工作

<rewrite> 
     <globalRules> 
      <rule name="redirect"> 
       <match url="/admin" /> 
       <conditions> 
        <add input="{REMOTE_ADDR}" pattern="10.30.*.*" negate="true" /> 
       </conditions> 
       <action type="Rewrite" url="/error" /> 
      </rule> 
     </globalRules> 
    </rewrite> 

這裏有什麼明顯的錯誤嗎?我希望任何外部流量嘗試點擊/管理以重定向到錯誤頁面,並且只允許單個內部IP塊訪問它。把我的頭髮拉出來。

+0

嗨,想出這裏的盒子。您是否在IIS中安裝了IIS HTTP重定向模塊? –

回答

0

匹配正則表達式存在問題。它不應該以斜槓開始。正確的是^admin^指URL的開始)

<rule name="redirect"> 
    <match url="^admin" /> 
    <conditions> 
     <add input="{REMOTE_ADDR}" pattern="10.30.*.*" negate="true" /> 
    </conditions> 
    <action type="Rewrite" url="/error" /> 
</rule> 

,我有兩點要注意:

1)IP驗證最好是有正則表達式一樣認爲:10.30.[0-9]{1,3}.[0-9]{1,3}代替10.30.*.*

2)取決於您的負載平衡器和網絡基礎設施,但您可能需要檢查{HTTP_X_Forwarded_For}標頭,而不是{REMOVE_ADDR},因爲客戶端的IP可能位於不同標頭中