Welcome to WebmasterWorld Guest from 54.163.157.48

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Good way to stop an IP range please ?

     
2:11 pm on Feb 6, 2011 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 26, 2004
posts: 377
votes: 0


Just as an example, if you wanted to block all IPs in the range of

39.91.224

would you use :

RewriteCond %{REMOTE_HOST} ^39.91.224.* [OR]

or :

RewriteCond %{REMOTE_HOST} ^39.91.224. [OR]

Any help much appreciated.

Dexie
2:19 pm on Feb 6, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member wilderness is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Nov 11, 2001
posts:5459
votes: 3


from the Forun Library near page top

Mod_Rewrite & Regular Expressions [webmasterworld.com]

* matches 0 or more of the characters or set of characters immediately before it. (EG a* would match the lowercase letter 'a' 0 or more times, (abc)* would match the phrase 'abc' 0 or more times, while [a-z]* would match 0 or more lowercase letters from 'a to z'.)
end of quote

In your instance, do you expect TWO trailing periods after the Class C range?

BTW, you need to escape the periods in Rewrite Cond.

^39\.91\.224\.
2:44 pm on Feb 6, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member wilderness is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Nov 11, 2001
posts:5459
votes: 3


RewriteCond %{REMOTE_HOST}


Also incorrect.

Use.

RewriteCond %{REMOTE_ADDR}
3:05 pm on Feb 6, 2011 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 26, 2004
posts: 377
votes: 0


Many thanks Wilderness, have changed the host part to addr, but didn't quite understand the other parts and di read though the link - sorry - should it be :

RewriteCond %{REMOTE_ADDR} ^39.91.224.* [OR]

or :

RewriteCond %{REMOTE_ADDR} ^39.91.224. [OR]

Also, I've used similar before, but with no escaping the numbers, and it's always worked ok, so what would be the reason for escaping the numbers please?
5:03 pm on Feb 6, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member wilderness is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Nov 11, 2001
posts:5459
votes: 3


NEITHER.

It should be:
RewriteCond %{REMOTE_ADDR} ^39\.91\.224\. [OR]

Please note; you've also other required lines missing in order for this to function.
In addition the [OR] would only be used if there was another IP range and in an additional line the followed this line and ended your "RewriteCond test".
EX:
#may also require "RewriteEngine on", if NOT turned on prevuiously
RewriteCond %{REMOTE_ADDR} ^123\.456\.789\. [OR]
RewriteCond %{REMOTE_ADDR} ^234\.567\.789\.
RewriteRule .* - [L]

Please note these IP ranges were just used as an example and are without any intended significance
5:10 pm on Feb 6, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member wilderness is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Nov 11, 2001
posts:5459
votes: 3


Also, I've used similar before, but with no escaping the numbers, and it's always worked ok, so what would be the reason for escaping the numbers please?


From the same Forum Library and RegEx link I provided previously. A simple search on that page of "escape" would have located the reference.

\ is called an escaping character, this removes the function from a 'special character' (EG if you needed to match index.php?, which has both a . (dot) and a ?, you would have to 'escape' the special characters . (dot) and ? with a \ to remove their 'special' value it looks like this: index\.php\?)

Please note, if you failed to escape special characters in previous htaccess additions?
Than either those particular lines or your entire htaccess file would NOT function as you intended.
Syntax errors (failing to escape is one) provide a multitude of weird results.
I've had some syntax errors not provide a noticeable affect for months, then realized upon adding a new line that something was not functioning properly.
9:04 am on Feb 7, 2011 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 26, 2004
posts: 377
votes: 0


Many thanks - will do this now. One last thing, how on earth do you do the pipe character in the .htaccess file please?
9:15 am on Feb 7, 2011 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 26, 2004
posts: 377
votes: 0


Also, what is this part for please ?
RewriteRule .* - [L]


I know [L] means last command, but don't get the other part.
2:09 pm on Feb 7, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member wilderness is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Nov 11, 2001
posts:5459
votes: 3


it denies access all file requests.
Perhaps another may provide what it actually translates to.

how on earth do you do the pipe character in the .htaccess file please


The same way you do in any use. On your Keyboard is shown a split pipe character. Hold down the shift-key and select the split-pipe
2:29 pm on Feb 7, 2011 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 26, 2004
posts: 377
votes: 0


it denies access.
Perhaps another may provide what it actually translates to.

Sorry, don't understand. Are you saying that it denies access to the .htaccess file ?



how on earth do you do the pipe character in the .htaccess file please

The same way you do in any use. On your Keyboard is shown a split pipe character. Hold down the shift-key and select the split-pipe

Is it the one above the \
4:43 pm on Feb 7, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member wilderness is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Nov 11, 2001
posts:5459
votes: 3


Sorry, don't understand. Are you saying that it denies access to the .htaccess file ?


NO. It denies access to the IP range of the visitor (RewriteCond).

A "RewriteCond" requires a subsequent line (RewriteRule) which "applies that condition to".

NOT providing a RewriteRule is similar to saying "house" to somebody without providing any other explanation of the house or how it interacts with yourself or the person to whom you've said "house" to.
The house is blue.

Your overall htaccess file may have many individual sections, of all which impose different tasks.

Is it the one above the \


Yes.
9:40 pm on Feb 7, 2011 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 26, 2004
posts: 377
votes: 0


Many thanks - all sorted.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members