Forum Moderators: phranque

Message Too Old, No Replies

RewriteCond

.htaccess

         

xt35

8:40 am on Dec 31, 2005 (gmt 0)

10+ Year Member



I need to block the range #*$!.xxx.0.0 - xxx.xxx.112.255

Please show me the RewriteCond for that range.

Thank you.

xt35

7:52 am on Jan 8, 2006 (gmt 0)

10+ Year Member



Bump

It seems my simple question was bypassed :(

Please, let me know how to block the range ***.***.0.0 - ***.***.112.255. How must be the RewriteCond written for that?

Thanks

jdMorgan

4:50 pm on Jan 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Post your best effort at writing the code, and we will be glad to help.

For information on how to get the most from this forum, please check out our forum charter [webmasterworld.com].

For more information on mod_rewrite and regular expressions, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

xt35

9:32 pm on Jan 8, 2006 (gmt 0)

10+ Year Member



ok :)

Here is what I'm using now

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

Is it correct?

jdMorgan

12:31 am on Jan 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No. The reason is that regular expressions work on characters, and there is no "meaning" or "value" associated with them -- they are just characters. Regular expressions does accept character ranges, such as [a-z] and [3-7], but again, these are regex character ranges, and not scalar ranges.

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])\.

(You can ignore the final 0-255 octet of the IP address, since all values are to be matched (accepted).

Replace the broken pipe "¦" characters with solid pipe characters before use; Posting on this forum modifies that character.

Jim

xt35

8:17 pm on Jan 9, 2006 (gmt 0)

10+ Year Member



Jim, thank you very much for the explanation, now I think I understand a bit how should the ranges be written :)

I need a confirmation if the below samples are correct:

1.
to block from ***.***.0.0 - ***.***.63.255 the condition looks like ^***\.***\.([0-9]¦[1-6][0-3])\.

2.
to block from ***.160.0.0 - ***.162.255.255 the condition looks like ^***\.16[0-2]\.

Thanks again.

jdMorgan

5:40 pm on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That looks correct to me.

Jim

xt35

5:04 pm on Jan 12, 2006 (gmt 0)

10+ Year Member



Thank you Jim