homepage Welcome to WebmasterWorld Guest from 54.235.61.62
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Good way to stop an IP range please ?
Dexie




msg:4263248
 2:11 pm on Feb 6, 2011 (gmt 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

 

wilderness




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

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

wilderness




msg:4263251
 2:44 pm on Feb 6, 2011 (gmt 0)

RewriteCond %{REMOTE_HOST}


Also incorrect.

Use.

RewriteCond %{REMOTE_ADDR}

Dexie




msg:4263255
 3:05 pm on Feb 6, 2011 (gmt 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?

wilderness




msg:4263290
 5:03 pm on Feb 6, 2011 (gmt 0)

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

wilderness




msg:4263298
 5:10 pm on Feb 6, 2011 (gmt 0)

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.

Dexie




msg:4263492
 9:04 am on Feb 7, 2011 (gmt 0)

Many thanks - will do this now. One last thing, how on earth do you do the pipe character in the .htaccess file please?

Dexie




msg:4263495
 9:15 am on Feb 7, 2011 (gmt 0)

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


I know [L] means last command, but don't get the other part.

wilderness




msg:4263593
 2:09 pm on Feb 7, 2011 (gmt 0)

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

Dexie




msg:4263600
 2:29 pm on Feb 7, 2011 (gmt 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 \

wilderness




msg:4263675
 4:43 pm on Feb 7, 2011 (gmt 0)

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.

Dexie




msg:4263922
 9:40 pm on Feb 7, 2011 (gmt 0)

Many thanks - all sorted.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved