Htaccess Redirect

Job ID: 38178169

Budget: $10 – $30 USD

I want visits to a specific file redirected by htaccess if it matches an IP in a range and redirect to another URL if it does not match an IP in the range listed but is visiting the specific file (not in other cases).

I have made some tests already but can not figure out how to redirect if IP is not matched (only redirecting on root / domain) and also no idea how to integrate that the entire rules are just to be applied if a specific file is visited, ie. test.php

My test:

<IfModule mod_rewrite.c>
RewriteCond expr "-R '192.168.0.0/24'" [OR]
RewriteCond expr "-R '192.168.1.0/24'"
RewriteRule ^$ https://www.example.org [L,R=301]
</IfModule>

If I add
RewriteRule ^test.php$ - [L]
it does not work.

Desired result: If user with IP 192.168.0.1 is visiting test.php he is redirected to https://www.example.org. If user with IP 192.168.2.1 is visiting test.php he is redirected to https://www.example2.org. If IP 192.168.0.1 or 192.168.2.1 is visiting any other page except test.php nothing happens.
Related categories: PHP Linux Apache MySQL HTML