Forum Moderators: phranque
I need to do this with a "setenvifnocase request_uri" entry in the .htaccess.
I've tried a lot of regex's, but I cannot find a regex that 'catches' the URI above. I've tried things like this (complete .htaccess file):
ErrorDocument 401 /401.php
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php
AddOutputFilter INCLUDES .html
AddOutputFilter INCLUDES .htm
AddType application/x-httpd-php .html
setenvifnocase request_uri pb\.php\?$ bad_uri
<Limit GET POST>
Order Allow,Deny
Allow from all
Deny from env=bad_uri
</Limit>
(end of .htaccess)
Also a regex like "^(.*)pb\.php\?$" didn't work.
Can anyone help me with this one please?
Another example of an URI which I want to block: /forum/index.php?board=http://basink.web.id/n?
I need to do this with a "setenvifnocase request_uri" entry in the .htaccess.
You didn't make clear why you need to use SetEnvIf, but if you want to test the query string, you'll need to use mod_rewrite.
This sets the bad_uri variable as does SetEnvIf, or you could use an [F] flag on the rule to directly respond with a 403-Forbidden response:
RewriteCond %{QUERY_STRING} pb\.php\?$
RewriteRule ^forum/index.php$ - [E=bad_uri:1]
[edited by: jdMorgan at 7:55 pm (utc) on Oct. 30, 2007]
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^libwww-perl [OR]
RewriteCond %{HTTP_USER_AGENT} ^Wget
RewriteRule ^.*$ - [F]
While the following does work:
SetEnvIfNoCase User-Agent "^libwww-perl" bad_bot
SetEnvIfNoCase User-Agent "^Wget" bad_bot
<Limit GET POST>
order allow,deny
allow from all
deny from env=bad_bot
</Limit>
So I have two options: fixing the code which uses mod_rewrite, and use the solution which you provided, or block bad URI's the SetEnvIfNoCase-way. :)
So, is there anything wrong with the two RewriteCond-lines above?
[edited by: Snoader at 8:21 pm (utc) on Oct. 30, 2007]
How, specifically, did it "not work"?
Clients with user-agents we were trying to block, were not stopped by the .htaccess. I didn't have access to the server log-files, so I couldn't check any error messages. But on my local Apache-server, I didn't get any errors.
But, for some strange reason, it does work now! Maybe after complaining, the virtual host provider changed (corrected) something without telling us.
Anyway, thank you very much for your help, especially your remark about the query string. :)
Cheers,
Sander
Over the long term, consider moving to a host that provides full access to all log files -- It may save you countless hours of frustration and/or revenue loss.
Jim