There is an application that runs on , the site is available at http: // localhost / site1 . I have refactored the application (I fixed small cross-sections, added functionality), now I want to provide it to some users for testing .

On the server I created a new site: http: // localhost / site2 , where I posted the updated version of the application. Is it possible to redirect access to site1 users based on the ip list to site2 .

  • There is a module for ivers revers proxy for iis. If redirect is not needed, then you can risk it. Maybe there is an opportunity to choose the final site based on the visitor's ip. - Sergey

1 answer 1

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> 
  • and can you tell if the rule can be inverted , i.e. make the opposite rule for site2 to redirect all others to site1? - Bald
  • @Bald as an option, in the last example, add negate = "true": <add input = "{IPList: {REMOTE_ADDR}}" pattern = "1" negate = "true" />. And in url site1 respectively. - Ella Svetlaya