Forum Moderators: phranque
What I want to do is use apache to redirect any of those IPs to another site, instead of accessing my main site.
The list is pretty big so I also have to be careful this doesn`t cause any extra "stress" on the server.
How can this be done with .htaccess?
Thanks!
Welcome to WebmasterWorld!
The problem is that CIDR specifications are only understood by mod_access, which --as far as I know-- is only able to allow or deny access, i.e. either do nothing, or generate a 403-Forbidden response.
You can use mod_rewrite to do a conditional redirect based upon IP address ranges, but they have to be expressed as purely-text patterns (that is, with no numeric meaning).
So:
RewriteCond %{REMOTE_ADDR} ^58\.1[45]\. [OR]
RewriteCond %{REMOTE_ADDR} ^58\.(1[6-9]¦2[0-3])\. [OR]
RewriteCond %{REMOTE_ADDR} ^58\.2[45]\.
RewriteRule .* http://www.example.com/ [R=301,L]
You could use an on-line CIDR-to-IP-range converter to make this job easier, but other than re-using the patterns you write for more than one line, there's not much that can be done short of writing a script to speed up the work.
Jim