使用web.config重定向特定的IP范围

时间:2018-07-12 11:44:48

标签: web-config web.config-transform

我想使用web.config文件重定向特定的IP范围

我不熟悉web.config

这是我的代码

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <clear />
            <rule name="Redirect Japan Users" stopProcessing="true">
                <match url=".*" />
                <conditions>
                    <add ipAddress="83.116.119.0" subnetMask="255.255.255.0"/>
                </conditions>
                <action type="Redirect" url="http://www.example.net/jp/" redirectType="Permanent" appendQueryString="false" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>
</configuration>

1 个答案:

答案 0 :(得分:1)

Try this:
//Block a particular IP
<security>
   <ipSecurity allowUnlisted="true">          
       <clear/>               
       <add ipAddress="IPTOBEBLOCKED"/>          
   </ipSecurity>
</security>

//Redirect an IP to another domain
<rule name="Redirect Japan Users" enabled="true" stopProcessing="false">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="IPTOBEBLOCKED"/>
    </conditions>
    <action type="Redirect" url="http://www.example.net/jp/" redirectType="Permanent" appendQueryString="false" />
</rule>