Forum Moderators: phranque

Message Too Old, No Replies

RewriteCond

         

xt35

7:25 pm on Apr 15, 2006 (gmt 0)

10+ Year Member



Hello,

I have a problem. I've blocked the range x.x.0.0 - x.x.31.255 with the following

RewriteCond %{REMOTE_ADDR} ^x\.x\.([0-9]¦[1-3][01])\. [OR]

When I checked my logs today I've found that the IP x.x.23.14 accessed my website successfully. Is my above RewriteCond wrong?

Thanks.

jdMorgan

2:24 am on Apr 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I've blocked the range x.x.0.0 - x.x.31.255 with the following

RewriteCond %{REMOTE_ADDR} ^x\.x\.([0-9]¦[1-3][01])\. [OR]

This blocks 0-9, 10, 11, 20, 21, 30, & 31 only.

Always remember that RewriteCond is doing a text character compare, and not a true nummeric range evaluation.

A more-correct regex for .0. - .31. would be \.([12]?[0-9]¦3[01])\.

Jim

xt35

7:14 am on Apr 16, 2006 (gmt 0)

10+ Year Member



Thank you Jim.

I'm a bit confused now :/ A while ago you've written the following:

**********************************************

In order to match a numeric range of 0-112, you have to cover all possible character combinations:

[0-9] for 0-9
[1-9][0-9] for 10-99
10[0-9] for 100-109
11[012] for 110-112

So the whole mess, when put together, looks like this:

^***\.***\.([0-9]¦[1-9][0-9]¦10[0-9]¦11[012])\.

You can shorten that slightly, to:

^***\.***\.([1-9]?[0-9]¦10[0-9]¦11[012])\.

**********************************************

In the above example, you used [1-9][0-9] for the range 10-99. In my case, I used [1-3][01] for the range 10-31. Isn't that the same logic?

xt35

7:25 am on Apr 16, 2006 (gmt 0)

10+ Year Member



Please, can you explain what exactly means the "?" from "[12]?[0-9]"?

Thanks.

jdMorgan

3:12 pm on Apr 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is a regular-expressions token that make the preceding character, chatacter-group, or sub-pattern optional.

So [12]?[0-9] means 0 through 9, 10 through 19, or 20 through 29.

You could write that more clearly but less efficiently as [0-9]¦[1-2][0-9]

For more information, see the regular-expressions turtorial cited in our forum charter [webmasterworld.com]. There are also many "better" regex tutorials on the Web, but this one is short and to the point.

Jim

xt35

3:56 pm on Apr 16, 2006 (gmt 0)

10+ Year Member



Yes, thanks Jim.