Forum Moderators: phranque

Message Too Old, No Replies

RewriteCond problem

         

xt35

8:34 am on Feb 5, 2006 (gmt 0)

10+ Year Member



I'm trying to block the range 000.000.64.0 - 000.000.127.255 and I've written the following condition:

RewriteCond %{REMOTE_ADDR} ^000\.000\.([6-9]¦[4-9][0-9]¦10[0-9]¦1[12][0-7])\.$

I've thought the condition is written correctly, since today when I've seen in my logs that 000.000.88.162 was successfully accessing my website. Can someone explain why my condition isn't good and how it should be written?

Thanks.

jdMorgan

3:01 pm on Feb 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm trying to block the range 000.000.64.0 - 000.000.127.255 and I've written the following condition:

RewriteCond %{REMOTE_ADDR} ^000\.000\.([6-9]¦[4-9][0-9]¦10[0-9]¦1[12][0-7])\.$

RewriteCond uses a string compare. That is, it compares characters, not numerical values. So it is necessary to break the problem into several pieces:

First, since the last octet is 0-255 --the entire valid range of an octet-- we can ignore it completely. I won't show the first two digits here either, because they don't change.

Range ........... Pattern 
64.0. -- 69.255. 6[4-9]\.
70.0. -- 99.255. [7-9][0-9]\.
100.0. - 119.255. 1[01][0-9]\.
120.0. - 127.255. 12[0-7]\.

Now put this all together by ORing the four lines:

( 6[4-9] ¦ [7-9][0-9] ¦ 1[01][0-9] ¦ 12[0-7] ) \.

Finally, add the RewriteCond, a start anchor, and the fixed parts of the pattern, and remove the extra whitespace:


RewriteCond %{REMOTE_ADDR} ^000\.000\.(6[4-9]¦[7-9][0-9]¦1[01][0-9]¦12[0-7])\.

You don't need any end-anchor, since we are ignoring the final octet completely.

Replace the broken pipe "¦" characters above with solid pipes before trying to use this code; Posting on this forum modifies the pipe character, and will cause a server error if not corrected.

Jim

xt35

4:53 pm on Feb 5, 2006 (gmt 0)

10+ Year Member



Thanks again Jim. Yes, I've also broke the problem into pieces, but a bit different (and wrong, it seems).

On my server, the broken pipe "¦" don't give any error :)

jdMorgan

5:14 pm on Feb 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It will likely give a functional error if not a server error, because it won't be correctly interpreted as meaining "OR".

Replace those characters with solid pipes -- Use SHIFT-\ on most U.S. 101-key keyboards.

Jim

xt35

9:52 pm on Feb 5, 2006 (gmt 0)

10+ Year Member



Yes, I've already replaced them with solid pipes. I'm not sure if it was functioning correctly 100%, but at few tests it seemed OK.