Tell me how to create a forwarding directive in htaccses with the definition condition by ip

Example:

если ip=2.2.2.2 или 3.3.3.3 то 301 редирект на site.ru 

    1 answer 1

     RewriteEngine On RewriteCond %{REMOTE_ADDR} ^2\.2\.2\.2$ [OR] RewriteCond %{REMOTE_ADDR} ^3\.3\.3\.3$ RewriteRule .* http://site.ru/ [R=301,L] 

    UPD Online calculators say that for 86.102.72.240/28 ->

     Хост(min): 86.102.72.241 Хост(max): 86.102.72.254 

    then the whole range can be written in one regular order and the rule will be:

     RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?site\.org RewriteCond %{REMOTE_ADDR} ^86\.102\.72\.2(4[1-9]|5[0-4])$ RewriteRule .* http://site.ru/ [R=301,L] 
    • aha thanks then one more question, even two) following the logic then provided in RewriteCond there will be something like RewriteCond% {HTTP_HOST} ^ site \ .org [AND] RewriteCond% {REMOTE_ADDR} ^ 2 \ .2 \ .2 \ .2 $ RewriteRule. * Site.ru [R = 301, L]? and what to do there is an ip pool large enough not to prescribe each separately? - Broouzer King
    • @BroouzerKing, I didn’t understand anything from the first one, from the second one, you can specify not exact ip, but subnets in the form of RewriteCond %{REMOTE_ADDR} ^3\.3\.3\. , RewriteCond %{REMOTE_ADDR} ^3\.3\. . Or do not load .htaccess rules, and move all the logic from it to the router ru.stackoverflow.com/questions/542869/… - Visman
    • on the first point, there is already a condition for redirecting ala RewriteCond% {HTTP_HOST} ^ site \ .org as to add current conditions to this condition. on the second. I'm drowning the evening, I had to write right away that I have a pool of these same subnets, for example, 86.102.72.240/28 and there is a lot of such good - Broouzer King
    • Thanks for the link, I read it, but in this case it will not work. This is if you can put it that way. it is empty there is no cms and there is nothing at all except the htaccess file, I can download the php file with the same routing, but I would like to use it in htaccess. in this case “nailing” as aptly put it in that question - Broouzer King
    • @BroouzerKing, updated the answer. - Visman