I think the easiest way to do this is using the IIS URL Rewrite module, in which we create a rule based on the specified IP.
Here is an example of a rule that, based on a specific IP address, redirects a user to another address:
<rule name="Redirect by IP" stopProcessing="true"> <match url=".*" /> <conditions> <add input="{REMOTE_ADDR}" pattern="10.10.10.*" /> </conditions> <action type="Redirect" url="http://localhost/site2" /> </rule>
If there are not many addresses, you can list them in the following conditions:
<conditions logicalGrouping="MatchAny"> <add input="{REMOTE_ADDR}" pattern="10.10.10.5" /> <add input="{REMOTE_ADDR}" pattern="20.20.30.15" /> <add input="{REMOTE_ADDR}" pattern="30.30.20.44" /> </conditions>
If there are many addresses, you can use Rewrite Maps :
<rewrite> <rules> <rule name="Redirect by IP" stopProcessing="true"> <match url=".*" /> <conditions> <add input="{IPList:{REMOTE_ADDR}}" pattern="1" /> </conditions> <action type="Redirect" url="http://localhost/site2" /> </rule> </rules> <rewriteMaps> <rewriteMap name="IPList"> <add key="10.10.10.5" value="1" /> <add key="20.20.30.15" value="1" /> <add key="30.30.20.44" value="1" /> <add key="40.40.40.2" value="1" /> </rewriteMap> </rewriteMaps> </rewrite>