You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Mike <mi...@levrah.net> on 2002/11/07 22:47:04 UTC

[users@httpd] Multiple uses of RewriteRule(s)/Cond(s) in same .htaccess

Hello folks.

This is my first post here. Try not to throw too many tomatoes. :) Since 
this is my first post, I'm not sure whether posting code/example-directives 
is allowed or not. So I'm going to err on the side of safety, and not post 
the code to which my question refers. If posting code is allowed, please 
advise and I will follow-up.

The question: In utilizing RewriteEngine, will multiple uses of 
RewriteRule(s) and RewriteCond(s) within the same .htaccess file result in 
unexpected behavior/results? I'm wanting to make sure the directives 
(cond/rule pairs) will work independently, or that they won't cancel one 
another out. I can post an example of what I'm doing if allowed...

Thanks!
-mike


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Multiple uses of RewriteRule(s)/Cond(s) in same .htaccess

Posted by Joshua Slive <jo...@slive.ca>.
On Thu, 7 Nov 2002, Mike wrote:
> The code fundamentally works perfectly. Both of these work independently
> just fine. I just want to be sure when combining them together into one
> .htaccess, that I'm not going to cause the server to blow a gasket. :)

It seems fine to me.  If the first set of rules match, then the second set
will likely have no effect, but that seems fine in this case.

Joshua.



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Multiple uses of RewriteRule(s)/Cond(s) in same .htaccess

Posted by Mike <mi...@levrah.net>.
At 03:52 PM 11/7/2002, you wrote:
>On Thu, 7 Nov 2002, Mike wrote:
> > The question: In utilizing RewriteEngine, will multiple uses of
> > RewriteRule(s) and RewriteCond(s) within the same .htaccess file result in
> > unexpected behavior/results? I'm wanting to make sure the directives
> > (cond/rule pairs) will work independently, or that they won't cancel one
> > another out. I can post an example of what I'm doing if allowed...
>
>Yep, post the configuration excerpt.
>
>In general, RerwiteRule/RewriteCond are processed in the order they are
>seen in the config file.  But there are lots of ways to short-circuit that
>using options to the RewriteRules.
>
>Joshua.

This is the short version. Other conditions exist in the first section. I 
didn't want to overwhelm with excessive paste when only one line is needed 
for the question.

The code fundamentally works perfectly. Both of these work independently 
just fine. I just want to be sure when combining them together into one 
.htaccess, that I'm not going to cause the server to blow a gasket. :)

##############################
# Turn RewriteEngine ON
RewriteEngine on

# Protect site against webscrapers
RewriteCond %{HTTP_USER_AGENT} ^contrpl [NC,OR]
...other conditions exist here...
RewriteCond %{HTTP_USER_AGENT} ^wget [NC]
RewriteRule ^.* - [forbidden]

# Protect against off-site graphic linking
RewriteRule (.*/illegal-link.gif) $1 [last]
RewriteCond %{HTTP_REFERER} !^($|(http://)?[^/]*(foo|bar)) [NC]
RewriteRule \.(jpe?g|gif|png) http://www.blah.com/illegal-link.gif [R]
##############################

Disclaimer: Yes. I know there is no real, tried-n-true, completely 
reliable, always-going-to-work way to protect against 
web-harvesting/scraping, nor image/bandwidth theft. But I do want to do 
whatever I can. If this post results in another thread showing other ways 
to do same, that's fine too. hehe But I've been using the above two 
configurations separately on different webs with successful some time. All 
I want to do now is combine the two together. :)

Thanks!
-mike


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Multiple uses of RewriteRule(s)/Cond(s) in same .htaccess

Posted by Joshua Slive <jo...@slive.ca>.
On Thu, 7 Nov 2002, Mike wrote:
> The question: In utilizing RewriteEngine, will multiple uses of
> RewriteRule(s) and RewriteCond(s) within the same .htaccess file result in
> unexpected behavior/results? I'm wanting to make sure the directives
> (cond/rule pairs) will work independently, or that they won't cancel one
> another out. I can post an example of what I'm doing if allowed...

Yep, post the configuration excerpt.

In general, RerwiteRule/RewriteCond are processed in the order they are
seen in the config file.  But there are lots of ways to short-circuit that
using options to the RewriteRules.

Joshua.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org