2013-02-27 104 views
0

對於網站安全性,我想使用web.config將單個IP地址或幾個IP地址重定向到不同的域。我對此很陌生。我知道如何限制訪問權限或阻止某些IP,但有沒有簡單的重定向方法?謝謝!web.config通過ip重定向

回答

0

重定向某些IP地址,您將需要使用URL redirect rules engine可供IIS 7

檢查此鏈接瞭解如何通過IP地址重定向指令: https://webmasters.stackexchange.com/questions/31509/web-config-to-redirect-except-some-given-ips

<rewrite> 
    <rules> 
    <rule name="Imported Rule 1" stopProcessing="true"> 
     <match url="(.*)$" ignoreCase="false" /> 
     <conditions> 
     <add input="{REMOTE_HOST}" pattern="^123\.123\.123\.123" ignoreCase="false" negate="true" /> 
     </conditions> 
     <action type="Redirect" redirectType="Found" url="/coming-soon.html" /> 
    </rule> 
    </rules> 
</rewrite> 
+0

謝謝,維克多。有沒有辦法做到這一點,它只是重定向來自某些IP的請求? – user2117017 2013-02-27 20:36:30

+0

您好,以上答案。我希望這個解決方案適合你。 – Victor 2013-02-27 20:43:18

1

無法回覆以Victor的評論,所以我會把我編輯的代碼放在這裏,而不是建議更改。

<rewrite> 
    <rules> 
    <rule name="Imported Rule 1" stopProcessing="true"> 
     <match url="(.*)$" ignoreCase="false" /> 
     <conditions> 
     <add input="{REMOTE_HOST}" pattern="^123\.123\.123\.123" ignoreCase="false" negate="true" /> 
     </conditions> 
     <action type="Redirect" redirectType="Found" url="http://www.domain-to-redirect-to/coming-soon.html" /> 
    </rule> 
    </rules> 
</rewrite> 

這裏的變化是,它重定向到一個新的域作爲提問者想要的東西,而不是在同一個域中的頁面。

請注意,如果您想在同一個域名上重定向到coming-soon.html,則需要更改匹配規則,否則您將被置於重定向循環中。

這樣:

<rewrite> 
    <rules> 
    <rule name="Imported Rule 1" stopProcessing="true"> 
     <match url="(.*)coming-soon.html$" ignoreCase="false" negate="true" /> 
     <conditions> 
     <add input="{REMOTE_HOST}" pattern="^123\.123\.123\.123" ignoreCase="false" negate="true" /> 
     </conditions> 
     <action type="Redirect" redirectType="Found" url="/coming-soon.html" /> 
    </rule> 
    </rules> 
</rewrite>