Block IP Addresses using Map File

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 1
Joined: 31 May 2012, 17:48

Block IP Addresses using Map File

31 May 2012, 17:53

I'm trying to create a map file with a list of ip address I would like to block.

mapfileBlockedIPs.txt contains one line which is my ip address.

162\.40\.252\.25

I have written a rule to use this list of ip's and return a Forbidden if matched.

RewriteMap mapfileBlockedIPs txt:D:\DLLs\ISAPI\mapfileBlockedIPs.txt
RewriteCond %{REMOTE_ADDR} (.*)
RewriteCond ${mapfileBlockedIPs:${%1}|NOT_FOUND} !NOT_FOUND
RewriteRule (.*) - [F]


For some reason this never matches and does not block my ip.

When I try the rule without a map file the match does occur and my ip is blocked.

RewriteCond %{REMOTE_ADDR} 162\.40\.252\.25
RewriteRule (.*) - [F]


What am I doing wrong?

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

Re: Block IP Addresses using Map File

01 Jun 2012, 05:37

Hello,

Firstly make you mapfile look like:

Code: Select all
162.40.252.25     162.40.252.25


and edit your rule as in following:

RewriteMap mapfileBlockedIPs txt:D:\DLLs\ISAPI\mapfileBlockedIPs.txt

Code: Select all
RewriteCond %{REMOTE_ADDR} (.*)
RewriteCond ${mapfileBlockedIPs:%1|NOT_FOUND} !NOT_FOUND
RewriteRule (.*) - [F]


Regards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 10 guests