Yuseferi
Yuseferi

Reputation: 8710

Redirect based on IPs ranges on .htaccess

I know it's possible to redirect on .taccess based on IP, as an instnace

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !=123.45.67.89
RewriteRule index.php$ /construction.php [R=301,L]

but what I'm looking for is redirect based on IPs range, I mean 123.45.67.89 to 123.45.67.120 95.4.63.0 to 95.4.63.200

How redirect user on .htaccess based on IPs ranges?

Upvotes: 1

Views: 33

Answers (1)

anubhava
anubhava

Reputation: 785866

You can use regex to check numeric ranges also. For your examples following rule should work:

RewriteEngine On

RewriteCond %{REMOTE_ADDR} ^123\.45\.67\.(89|9\d|1[01]\d|120)$ [OR]
RewriteCond %{REMOTE_ADDR} ^95\.4\.63\.(\d|[1-9]\d|1\d{2}|200)$
RewriteRule ^index\.php$ /construction.php [R=301,NC,L]

Upvotes: 1

Related Questions