Multiple Conditions dont work

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 4
Joined: 16 May 2012, 07:03

Multiple Conditions dont work

16 May 2012, 07:21

Tried to deny users whose ip dont in the specified ip range and not WINXP IE7\8 visiting my website,

configuration file as below:

# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.89
RewriteEngine On
#allow 201.224.100.x only
RewriteCond %{REMOTE_ADDR} !201\.224\.100\.d{1,3}$
#allow xp ie78 only
RewriteCond %{HTTP:User-Agent} !MSIE\ [78]\.[0]\;\ Windows\ NT\ [5]\.[1] [NC]

RewriteRule .* - [F]

it doesnt work, does anyone have idea about that?

How could I write the sencond condition in two parts, it dosent work as below:

#Match NOT IE68
RewriteCond %{HTTP:User-Agent} !MSIE\ [68] [NC]
#Match NOT XP
RewriteCond %{HTTP:User-Agent} !NT\ [5]\.[1] [NC]
Last edited by tmdsb on 18 May 2012, 03:59, edited 3 times in total.

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

Re: Multiple Conditions dont work

16 May 2012, 07:28

We can only find out if you provide rewrite.log for a testing request.
Logging issues described in FAQ

Regards
Andrew

User avatar
Posts: 4
Joined: 16 May 2012, 07:03

Re: Multiple Conditions dont work

16 May 2012, 07:47

My Conf file:

RewriteEngine On
#Match NOT IE68
RewriteCond %{HTTP:User-Agent} !MSIE\ [68] [NC]
#Match NOT XP
RewriteCond %{HTTP:User-Agent} !NT\ [5]\.[1] [NC]
RewriteRule .* [NF]


Here is the log:

Code: Select all
(2) init rewrite engine with requested uri /eurl.axd/05cde567faa7ec44b0b9e8d9ba8a38f5/
 (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
 (1) Htaccess process request c:\inetpub\wwwroot\.htaccess
 (3) applying pattern '^(.*)$' to uri 'eurl.axd/05cde567faa7ec44b0b9e8d9ba8a38f5/'
 (4) RewriteCond: input='Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)' pattern='MSIE\x20[68]' => not-matched

 (2) init rewrite engine with requested uri /pagerror.gif
 (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
 (1) Htaccess process request c:\inetpub\wwwroot\.htaccess
 (3) applying pattern '^(.*)$' to uri 'pagerror.gif'
 (4) RewriteCond: input='Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)' pattern='MSIE\x20[68]' => not-matched

(2) init rewrite engine with requested uri /eurl.axd/05cde567faa7ec44b0b9e8d9ba8a38f5/
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(1) Htaccess process request c:\inetpub\wwwroot\.htaccess
(3) applying pattern '^(.*)$' to uri 'eurl.axd/05cde567faa7ec44b0b9e8d9ba8a38f5/'
(4) RewriteCond: input='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)' pattern='MSIE\x20[68]' => not-matched

 (2) init rewrite engine with requested uri /eurl.axd/05cde567faa7ec44b0b9e8d9ba8a38f5/
 (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
 (1) Htaccess process request c:\inetpub\wwwroot\.htaccess
 (3) applying pattern '^(.*)$' to uri 'eurl.axd/05cde567faa7ec44b0b9e8d9ba8a38f5/'
 (4) RewriteCond: input='Opera/9.80 (Windows NT 6.1; WOW64; U; en) Presto/2.10.229 Version/11.64' pattern='MSIE\x20[68]' => matched
 (4) RewriteCond: input='Opera/9.80 (Windows NT 6.1; WOW64; U; en) Presto/2.10.229 Version/11.64' pattern='NT\x20[5]\.[1]' => matched
 (1) Rewrite URL to >> /[NF]
 (2) rewrite 'eurl.axd/05cde567faa7ec44b0b9e8d9ba8a38f5/' -> '/[NF]'
 (2) internal redirect with /[NF] [INTERNAL REDIRECT]



thanks for your reply.

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

Re: Multiple Conditions dont work

16 May 2012, 09:24

I edited you log, so it's easier to read. I see the last request looks okay.

I think all you need is to replace
Code: Select all
RewriteRule .* [NF]
with
Code: Select all
RewriteRule .* - [F]

User avatar
Posts: 4
Joined: 16 May 2012, 07:03

Re: Multiple Conditions dont work

17 May 2012, 00:19

THE RULE:
RewriteEngine On

#Match Not 192.168.1.x
RewriteCond %{REMOTE_ADDR} !192\.168\.1\.\d{1,3}$

#Match NOT IE6\8 & NT5.1
RewriteCond %{HTTP:User-Agent} !MSIE\ [68]\.[0]\;\ Windows\ NT\ [5]\.[1] [NC]

#Show 403 - Forbidden
RewriteRule .* - [F]


PART 1 OF THE LOG:
NT5.1 WITH IE8,IP:192.168.10.131

(2) init rewrite engine with requested uri /eurl.axd/05cde567faa7ec44b0b9e8d9ba8a38f5/
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(1) Htaccess process request c:\inetpub\wwwroot\.htaccess
(3) applying pattern '.*' to uri 'eurl.axd/05cde567faa7ec44b0b9e8d9ba8a38f5/'
(4) RewriteCond: input='192.168.10.131' pattern='192\.168\.1\.\d{1,3}$' => matched
(4) RewriteCond: input='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)' pattern='MSIE\x20[68]\.[0]\;\x20Windows\x20NT\x20[5]\.[1]' => not-matched
(2) init rewrite engine with requested uri /pagerror.gif
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(1) Htaccess process request c:\inetpub\wwwroot\.htaccess
(3) applying pattern '.*' to uri 'pagerror.gif'
(4) RewriteCond: input='192.168.10.131' pattern='192\.168\.1\.\d{1,3}$' => matched
(4) RewriteCond: input='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)' pattern='MSIE\x20[68]\.[0]\;\x20Windows\x20NT\x20[5]\.[1]' => not-matched


PART 2 OF THE LOG:
NT5.2 WITH IE8,IP:192.168.1.13

(2) init rewrite engine with requested uri /eurl.axd/05cde567faa7ec44b0b9e8d9ba8a38f5/
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(1) Htaccess process request c:\inetpub\wwwroot\.htaccess
(3) applying pattern '.*' to uri 'eurl.axd/05cde567faa7ec44b0b9e8d9ba8a38f5/'
(4) RewriteCond: input='192.168.1.13' pattern='192\.168\.1\.\d{1,3}$' => not-matched
(2) init rewrite engine with requested uri /pagerror.gif
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(1) Htaccess process request c:\inetpub\wwwroot\.htaccess
(3) applying pattern '.*' to uri 'pagerror.gif'
(4) RewriteCond: input='192.168.1.13' pattern='192\.168\.1\.\d{1,3}$' => not-matched


PART 3 OF THE LOG:
NT6 WITH IE8,IP:192.168.1.28

(2) init rewrite engine with requested uri /eurl.axd/05cde567faa7ec44b0b9e8d9ba8a38f5/
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(1) Htaccess process request c:\inetpub\wwwroot\.htaccess
(3) applying pattern '.*' to uri 'eurl.axd/05cde567faa7ec44b0b9e8d9ba8a38f5/'
(4) RewriteCond: input='192.168.1.28' pattern='192\.168\.1\.\d{1,3}$' => not-matched
(2) init rewrite engine with requested uri /pagerror.gif
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(1) Htaccess process request c:\inetpub\wwwroot\.htaccess
(3) applying pattern '.*' to uri 'pagerror.gif'
(4) RewriteCond: input='192.168.1.28' pattern='192\.168\.1\.\d{1,3}$' => not-matched


Result:
PART 1: IP Address was MATCHED, User-Agent was not, the rewrite rule was not working!
PART 2: User-Agent was MATCHED, IP Address was not, it should have been found in the log, the rewrite rule was not working!
PART 3: Same as a PART 2

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

Re: Multiple Conditions dont work

18 May 2012, 08:11

Well, there's still no misbehave. In your first request the first condition matched, buth the other one didn't, so rule didn't work.

(4) RewriteCond: input='192.168.10.131' pattern='192\.168\.1\.\d{1,3}$' => matched
(4) RewriteCond: input='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)' pattern='MSIE\x20[68]\.[0]\;\x20Windows\x20NT\x20[5]\.[1]' => not-matched


In case you want those conditions to work like "either... or..." than you need to place [OR] flag after the first condition.

regards
Andrew

User avatar
Posts: 4
Joined: 16 May 2012, 07:03

Re: Multiple Conditions dont work

21 May 2012, 04:33

Thanks Andrew, I got it.

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 7 guests