homepage Welcome to WebmasterWorld Guest from 54.204.58.87
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
multiple RewriteEngine on
syntax
jim_w




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

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.

 

bird




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

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.

jdMorgan




msg:1509560
 4:41 pm on May 15, 2003 (gmt 0)

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

jim_w




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

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

jdMorgan




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved