【问题标题】:web.config redirect by ipweb.config 通过 ip 重定向
【发布时间】:2013-02-27 20:27:59
【问题描述】:

为了网站安全,我想使用 web.config 将单个 IP 地址或几个 IP 地址重定向到不同的域。我是新手。我知道如何限制访问或阻止某些 IP,但是有没有简单的重定向方法?谢谢!

【问题讨论】:

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


    【解决方案1】:

    要重定向某些 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>
    

    【讨论】:

    • 谢谢,维克多。有没有办法做到这一点,它只重定向来自某些 IP 的请求?
    【解决方案2】:

    无法回复 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-25
      • 1970-01-01
      • 1970-01-01
      • 2012-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-24
      相关资源
      最近更新 更多