Forum Moderators: phranque
I remember that, I think it was jdmorgan said, you could put multiple RewriteEngine on in the .htaccess file. What is the syntax?
Is it like…
RewriteEngine on
#Get rid of file sucking utilities
RewriteCond %{HTTP_USER_AGENT} ^NetAnts* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^unknown* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Pompos* [NC,OR]
RewriteRule ^.*$ [your_domain.com...] [L,R]RewriteEngine on
#Get rid of graphic snatching thieves
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://your_domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.your_domain.com/.*$ [NC]
RewriteRule .*\.(gif¦GIF¦jpg¦JPG)$ - [F]
I have ppl now linking to my graphics. Grrrrrrr.
Actually, multiple RewriteEngine on directives are allowed so that you can put RewriteEngine off directives into your code. This allows you to disable blocks of RewriteRules for testing purposes, without having to delete them or comment them out:
RewriteEngine on
-some active rules-
RewriteEngine off
-some disabled rules-
RewriteEngine on
-some more active rules-
Here are a few "cleanups" you might also be able to use:
RewriteEngine on
#Get rid of file sucking utilities
RewriteCond %{HTTP_USER_AGENT} ^NetAnts [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^unknown [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Pompos [NC]
RewriteRule .* /noentry [L]
#Get rid of graphic snatching thieves
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?your_domain\.com [NC]
RewriteRule \.(gif¦jpg)$ - [NC,F]
HTH,
Jim
(One difference is that it does eliminate the external redirect for file-suckers, but most of those user-agents won't follow an external redirect anyway.)
For some reason I have some UA’s being sent to /noenty, and some not, and they are exactly the same UA's. So I have something messed up somewhere. I compared the UA's character by character, and see no difference. The problem is, that UA shouldn’t be redirected. So if I fix the above problem, I wonder if I send everyone to /noentry. That would be a bummer.
Note that the last RewriteCond before a RewriteRule must not contain an [OR] flag
Thanks for your help. Now to experiment and see how many ppl I can get into /noentry before I figure out where the problem is. ;-)
> I have some UA’s being sent to /noentry, and some not, and they are exactly the same UA's
Look for missing [OR] flags, and for incorrect start and/or end anchoring of the regular-expressions patterns used to match user-agent strings. More info on anchoring and regex patterns is available by following the links in this Introduction to mod_rewrite [webmasterworld.com] post.
HTH,
Jim