Forum Moderators: phranque
this is a short version of my htaccess:
RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} ^http://(www\.)?.*(-.)?adult(-.).*$ [OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?.*(-.)?backside(-.).*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?.*(-.)?words(-.).*$ [NC,OR]
# without domain extension
RewriteCond %{HTTP_REFERER} ^http://(www\.)?trafbanf2.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?trafbang.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?threethrees.*$ [NC,OR]
# and now with domain extension
RewriteCond %{HTTP_REFERER} ^http://(www\.)?seeontv.com*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?self-improving.com*$ [NC,OR]
RewriteRule .* - [F,L]
After I put it online they still show up in my awstats and in my raw logfiles with 200 response, schouldn't they get a 403? If I block the IP address they get a 403 but can't use IP blocking because they are not all from static IP addresses.
Any help would be highly appreciated, thank you so much, Andy
[edited by: jdMorgan at 10:53 pm (utc) on Jan. 4, 2006]
[edit reason] Obscure referrers and clean up keywords. [/edit]
Welcome to WebmasterWorld!
You must not include an [OR] flag on your last RewriteCond. These are used to logically OR RewriteConds, and have no meaning if you try to OR a RewriteCond with a RewriteRule. Your rule will be ignored, and you should see a syntax error warning in your server error log.
You can also simplify and shorten the code by removing all instances of ".*$" from your RewriteCond patterns. These characters at the end of a pattern do not change the bahaviour and just take up processing time.
Also, [L] used with [F] is redundant and can be eliminated.
Jim
The one below would be a go then:
RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} ^http://(www\.)?.*(-.)?adult(-.) [OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?.*(-.)?backside(-.) [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?.*(-.)?words(-.) [NC,OR]
# without domain extension
RewriteCond %{HTTP_REFERER} ^http://(www\.)?trafbanf2 [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?trafbang [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?threethrees [NC,OR]
# and now with domain extension
RewriteCond %{HTTP_REFERER} ^http://(www\.)?seeontv.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?self-improving.com [NC]
RewriteRule .* - [F]
thanks again, Andy
The meaning is "match a hyphen followed by any character, and create a back-reference containing those two characters for later use. I'm sure you don't need the back-reference, so that reduces the required pattern to "-." and saves some CPU time. I assume you're trying to match <domain name> hyphen <any character> with it...
Jim
Now I did what you suggested but still no success, I still have them in my log files:
ip68-109-***-131.lu.dl.cox.net - - [04/Jan/2006:21:53:50 -0800] "GET / HTTP/1.1" 200 28838 "http://changedbyme.com" "Mozilla/4.0 (compatible; MSIE 5.01; Windows 98)"
ip68-109-***-131.lu.dl.cox.net - - [04/Jan/2006:21:53:50 -0800] "GET / HTTP/1.1" 200 28832 ".) http: //www. changedbyme.com/vsearch.php" "Mozilla/4.0 (compatible; MSIE 5.01; Windows 98)"
ip68-109-***-131.lu.dl.cox.net - - [04/Jan/2006:21:53:50 -0800] "GET / HTTP/1.1" 200 28830 "http: //www. changedbyme.com/voodoo.php" "Mozilla/4.0 (compatible; MSIE 5.01; Windows 98)"
even I have this line in my htaccess for this referrer:
RewriteEngine on
#Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} ^http://(www\.)?changedbyme.com [NC,OR]
RewriteRule .* - [F]
They still get a 200 server response but it should be a 403. I know I could do it over the ip address but some of them change their ip address from time to time.
BTW I changed the domain name of the spam site and "destroyed" the url... just in case.
Do you have any suggestions? Thanks again, Andy
[edited by: jdMorgan at 5:17 pm (utc) on Jan. 5, 2006]
[edit reason] Obscured IP address in hostname [/edit]
The code should work fine if mod_rewrite is available to you, is enabled by the FollowSymLinks option, and if the code is in a location where it will be executed for the requests.
Note that these attempts will still appear in your logs; The only change will be that the server response code will show as a 403-Forbidden, and the byte count will reflect that of your 403 error page.
Jim
1. I will try both ways and see what happens
2. I can't see entries made by these referrers in the error logs
3. the htaccess is in the same folder as the html files, so it should work fine, all other things setup in htaccess work just fine as redirect for example.
mod_rewrite is available
I know they still will show up in my logs but they all have a 200 and not 403 unless I block the IP they used, then it will be 403, but I need to get it working with the referrer, it's really bad.
Andy
If any of these is not true, then the rule will fail.
This stuff (mod_rewrite) requires absolute precision, but there is no "magic" to it. Something is causing this code to fail or perhaps it is not running at all due to a problem outside this code itself.
If you cannot find any problems like those listed above, then start with a very short list of RewriteConds for referrers (like the three worst ones), and test that. If it works add just a few more and test again.
Jim
RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} ^http://(www\.)blabla\.net [OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)blabla-report-report\.co\.uk [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)blacky-mbl\.de [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)xxblablahomes [NC]
RewriteRule .* - [F]
These rules work with e.g.
[xxblablahomes.com...]
[xxblablahomes.net...]
[xxblablahomes.info...]
but they still fail with
xxblablahomes.com
xxblablahomes.net
xxblablahomes.info
I checked it in wannabrowser and also from a friends site I did add for test reasons.
Can you pls point me to the right direction to get it also work without the http and www, I'm sort of stuck with that, I'm so tired.... ;-) lol
Thank you again Jim, you're really a great help, Andy
To make the www optional, simply add a "?" after the paranthesized www -- that's why they were parenthesized in the first place:
RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} ^http://(www\.)?blabla\.net [OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?blabla-report-report\.co\.uk [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?blacky-mbl\.de [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?xxblablahomes [NC]
RewriteRule .* - [F]
For more information on regular expressions, see the regex tutorial cited in our forum charter [webmasterworld.com]
Jim
+http://blabla.de
and then he slip through.
Can you please give me a hint how can I catch any sign in front of the http? Is there a way at all?
Andy
RewriteCond %{HTTP_REFERER} ^\+?http://(www\.)?blabla\.net [OR]
RewriteCond %{HTTP_REFERER} http://(www\.)?blabla\.net [OR]
Jim