[英]URL Rewrite not working on IIS 10.0
我在IIS 10.0上使用URL重寫,並在服務器級別(applicationHost.config)配置了以下規則。 我也沒有在我的web.config中嘗試過它。
<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>
這里有什么明顯的錯誤嗎? 我希望嘗試點擊/ admin的所有外部流量都重定向到錯誤頁面,並且僅允許單個內部IP塊對其進行訪問。 把我的頭發拉過來。
您可能需要安裝“應用程序請求路由”,它是IIS的擴展,可在以下位置獲得: https : //www.iis.net/downloads/microsoft/application-request-routing
匹配正則表達式中存在問題。 它不應該以斜杠開頭。 正確的是^admin
( ^
表示網址的開頭)
<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可能在不同的標頭中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.