User Agent syntax
5 posts
• Page 1 of 1
User Agent syntax
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
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
Re: User Agent syntax
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.
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.
Re: User Agent syntax
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
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
Re: User Agent syntax
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!
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!
Re: User Agent syntax
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.
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.
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 12 guests