User Agent syntax

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 3
Joined: 06 Jun 2014, 13:53

User Agent syntax

06 Jun 2014, 14:00

Hello

I'm having trouble blocking a particular user agent. I've read other forum posts and I've tried this 9 ways 'til Sunday with no luck. I'm sure the issue is with incorrect syntax. Would anyone be able to assist? We have many rules below this that do simple URL redirects with no issues.

The agent I'm trying to block as it appears in the IIS logs: Mozilla/4.0+(compatible;+Synapse)

My rules currently:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/4\.0\+\(compatible;\+Synapse\) [NC]
RewriteRule .? - [F]

Thank you

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: User Agent syntax

09 Jun 2014, 10:15

Hello,

Actually your rule looks correct.
To check it better, please enable logging in httpd.conf by putting

RewriteLogLevel 9

and provide rewrite.log records for your test request.

User avatar
Posts: 3
Joined: 06 Jun 2014, 13:53

Re: User Agent syntax

09 Jun 2014, 11:36

Hi

OK - here are the results from the debug log from an offending user agent(I've stripped some of the pre and post info, but please let me know if you need to see more of the log)

(2) init rewrite engine with requested uri /index.cfm?page=-1%27
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(3) applying pattern '.?' to uri 'index.cfm'
(4) RewriteCond: input='Mozilla/4.0 (compatible; Synapse)' pattern='Mozilla/4\.0\+\(compatible;\+Synapse\)' => not-matched

User avatar
Posts: 3
Joined: 06 Jun 2014, 13:53

Re: User Agent syntax

09 Jun 2014, 11:53

Oh, after looking at the log again, I've figured it out.

I wasn't accounting for the spaces correctly. I've made the change and confirmed that it is now working and blocking the agent correctly. Instead of using the '+' signs, those are spaces so I needed to use the '\s' syntax.

Original rule:

RewriteCond %{HTTP_USER_AGENT} ^Mozilla/4\.0\+\(compatible;\+Synapse\) [NC]

Correct rule:

RewriteCond %{HTTP_USER_AGENT} ^Mozilla/4\.0\s\(compatible;\sSynapse\) [NC]

Thanks for your help! I didn't even think about turning on debug!

User avatar
Posts: 6
Joined: 26 Jun 2014, 09:15

Re: User Agent syntax

26 Jun 2014, 09:56

Very cool way to block specific user agents. I would like to work with this as well, but I would like to have a way to code branch DEPENDING on the agent found, and also output messages, so that if a useful bot comes in, I can direct it the right pages, but perform no or very little site parameters initialization, and possibly bypassing GLOBAL.ASA

And if fact, that is my next question, exactly WHEN in the sequence of processing code from the server, are the .htaccess and htconf.httpd files processed? In fact, more pointedly, do these process AFTER the GLOBAL.ASA, or before? I would assume AFTER.

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 12 guests