user10070358
user10070358

Reputation:

redirect specific ip range using web.config

I want to redirect a specific ip range using web.config file

Am not familiar with web.config

here ismy code

<?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>

Upvotes: 1

Views: 278

Answers (1)

Vid
Vid

Reputation: 81

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>

Upvotes: 1

Related Questions