RewriteMap to Block IP Addresses

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 18
Joined: 06 Apr 2012, 23:12

RewriteMap to Block IP Addresses

10 Apr 2012, 12:23

Hello,

My hosting provider says that Helicontech, the company that makes ISAPI Rewrite suggests that you have no more than 100 rules in the file; instead using map files for rules. Larger rule sets may not work or they may slow the site's response down. I don't understand how to do the RewriteMap file thing to block ip addresses in a text file that is referred to by the .htaccess file. Can you show me how to convert what I have?

In the .htaccess file, I have been trying to block large numbers of IP addresses from entering our site like this:

RewriteCond %{REMOTE_ADDR} 27\.135\.76\..*
RewriteRule (.*) $1 [F]

RewriteCond %{REMOTE_ADDR} 38\.124\.20\.4
RewriteRule (.*) $1 [F]

RewriteCond %{REMOTE_ADDR} 50\.57\.54\.70
RewriteRule (.*) $1 [F]

RewriteCond %{REMOTE_ADDR} 94\.23\..*\..*
RewriteRule (.*) $1 [F]

RewriteCond %{REMOTE_ADDR} 94\.75\.207\.36
RewriteRule (.*) $1 [F]

RewriteCond %{REMOTE_ADDR} 97\.86\.242\.27
RewriteRule (.*) $1 [F]

RewriteCond %{REMOTE_ADDR} 130\.85\.43\.6
RewriteRule (.*) $1 [F]

RewriteCond %{REMOTE_ADDR} 173\.77\.164\.121
RewriteRule (.*) $1 [F]

RewriteCond %{REMOTE_ADDR} 204\.111\.88\.173
RewriteRule (.*) $1 [F]

RewriteCond %{REMOTE_ADDR} 204\.111\.176\.83
RewriteRule (.*) $1 [F]

RewriteCond %{REMOTE_ADDR} 205\.155\.228\.150
RewriteRule (.*) $1 [F]

RewriteCond %{REMOTE_ADDR} 209\.59\.216\.109
RewriteRule (.*) $1 [F]

RewriteCond %{REMOTE_ADDR} 209\.172\.33\.230
RewriteRule (.*) $1 [F]

RewriteCond %{REMOTE_ADDR} 216\.129\.119\.41
RewriteRule (.*) $1 [F]

RewriteCond %{REMOTE_ADDR} 20\.133\.4\..*
RewriteRule (.*) $1 [F]

RewriteCond %{REMOTE_ADDR} 41\..*\..*\..*
RewriteRule (.*) $1 [F]

What would I need to put in the htaccess file and map file to replace this?

Thanks!
Shawn

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: RewriteMap to Block IP Addresses

11 Apr 2012, 06:16

Well, there's also another option. So you have 2 options:

Code: Select all
# option #1 without mapfile
RewriteCond %{REMOTE_ADDR} (?:50\.57\.54\.70|94\.75\.207\.36|205\.155\.228\.150|209\.172\.33\.230)
RewriteRule (.*) $1 [F]


Code: Select all
# option #2
RewriteCond %{REMOTE_ADDR} (.*)
RewriteCond ${mapfile:%1|NOT_FOUND} !NOT_FOUND
RewriteRule .? - [F]

NOTE: you mapfile should contain the following:
Code: Select all
94.75.207.36        94.75.207.36
204.111.88.173    204.111.88.173
209.59.216.109    209.59.216.109

Problem is that mapfile doesn't carry the regexp, so you won't be able to use expression like 27.135.76..*. Also, 100 rules is not a limit. Depending on the server load is could be over 1000.

Regards
Andrew

User avatar
Posts: 18
Joined: 06 Apr 2012, 23:12

Re: RewriteMap to Block IP Addresses

11 Apr 2012, 17:49

Thank you Andrew!

Excellent, that worked great!

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 22 guests