2013-02-27 111 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>