web.config通过ip重定向

时间:2013-02-27 20:28:00

标签: redirect web-config ip security ip-address

对于网站安全性,我想使用web.config将单个IP地址或几个IP地址重定向到其他域。我是新手。我知道如何限制访问或阻止某些IP,但是有一种简单的方法可以重定向吗?谢谢!

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

要重定向某些IP地址,您需要使用适用于IIS 7的URL redirect rules engine

检查此链接以获取有关如何通过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>