Forum Moderators: phranque
The syntax I'm currently using is as follows:
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://64.233.161.104/.*$ [NC]
... various other IPs ...
... certain approved domains, including my own ...
RewriteRule .*\.(jpg¦gif)$ http:// mydomain /hotlink.png [R,NC]
What would be the syntax for allowing a range of IPs? For instance, Google has 64.233.160.0 - 64.233.191.255. How would I allow all of these to display my images? I've noticed that the Google-cache IPs seem regularly to end with the same sets of digits, namely .100, .104, and .120. What would be the syntax for "all of the IPs within this range that terminate with one of these three endings"?
Thank you.
Eliz.
Try:
RewriteCond %{HTTP_REFERER} !^http://64\.233\.1([6-8][0-9]¦9[01])\.
> the Google-cache IPs seem regularly to end with the same sets of digits, namely .100, .104, and .120.
Something like:
RewriteCond %{HTTP_REFERER} !^http://63\.233\.[0-9]{1,3}\.(10[04]¦120)$
Have I just been lucky? Or am I not understanding something about the syntax in the .htaccess file?
Thank you.
Eliz.
RewriteCond %{REMOTE_ADDR} ^1.2.21.
is obviously intended to match the IP address range 1.2.21.0 - 1.2.21.255
but it also matches the IP address ranges:
102.21.0.0 - 102.21.255.255
112.21.0.0 - 112.21.255.255
122.21.0.0 - 122.21.255.255
...
182.21.0.0 - 182.21.255.255
192.21.0.0 - 192.21.255.255
because the unescaped period will happily match the digits 0 through 9.
So, in fact, where it was the intent to allow (or block, depending on the RewriteRule) 256 IP addresses, this actually allows (or blocks) 65536x10 + 256 addresses, or 655,616 addresses.
That's one example, and others exist. Rather than spending the time to figure out if I might have a problem, I just code them to be formally correct. Having developed that habit, I stick with it most of the time.
Jim