Welcome to WebmasterWorld Guest from 54.145.166.96

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

multiple RewriteEngine on

syntax

   
6:11 am on May 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I tried to do a search for this, but entering ‘multiple RewriteEngine on’ returned 1000’s of hits.

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]


Or what?

I have ppl now linking to my graphics. Grrrrrrr.

4:09 pm on May 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One instance is definitively all that is needed. Any repetitions will just be redundant, but probably don't hurt. The syntax is as in your example. Other than that, I think the only rule is that the first one must come before any other rewrite statements.
4:41 pm on May 15, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



jim_w,

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-

You don't need multiple RewriteEngine on directives in your case.

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]

This code should function exactly the same as before - it is simply more concise. (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.) Note that the last RewriteCond before a RewriteRule must not contain an [OR] flag!

HTH,
Jim

5:15 pm on May 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Got it. It is the RewriteRule that ends the RewriteCond block and not RewriteEngine off .

(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.)

That may explain some inconsistencies I am getting.

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

Opps. That happened when I hacked down the size of the RewriteCond because it is the size of Baltimore.

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. ;-)

5:48 pm on May 15, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



jim_w,

> 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

 

Featured Threads

Hot Threads This Week

Hot Threads This Month