Forum Moderators: phranque

Message Too Old, No Replies

RewriteCond question

in .htaccess

         

xt35

11:59 am on Dec 27, 2005 (gmt 0)

10+ Year Member



Hello,

To block the range 100.101.128.0 - 100.101.255.255 can be used something like this:

RewriteCond %{REMOTE_ADDR} ^100\.101\.(12[89]¦1[3-9][0-9]¦2[0-4][0-9]¦25[0-5])\.*$

I would like to know if it's possible to write that condition more simple, like:

RewriteCond %{REMOTE_ADDR} ^(100.101.[128-255].*)$

The above condition gives an Error 500. Can someone explain why?

Thank you,
xt

jdMorgan

11:31 pm on Dec 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, because mod_rewrite is doing a character-based compare: a lexical compare, not a numerical compare.

A correction is needed, and you can shorten the regex slightly:

RewriteCond %{REMOTE_ADDR} ^100\.101\.(12[89]¦1[3-9][0-9]¦2[0-5][0-9])\.

This actually allows 100.101.250-259\.0-255, but since you'll never get a request for an octet value above 255, it doesn't matter and saves a few characters. There is also no need to specify the final octet, since it won't matter either.

Jim

xt35

12:14 am on Dec 28, 2005 (gmt 0)

10+ Year Member



Thank you for the correction.

But I don't understand something. For blocking the range 100.101.0.0 - 100.101.112.255, the condition below works perfectly:

RewriteCond %{REMOTE_ADDR} ^(100.101.[0-112].*)$ [OR]

If I change it for the range 100.101.128.0 - 100.101.255.255 I receive an Error 500. Isn't that weird?

Also, please, can you show me the RewriteCond for the range 100.252.0.0 - 100.255.255.255?

Thanks,
xt