Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to optimize my .htaccess file to avoid performance issues.

In my .htaccess file I have something that looks like this:

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} bigbadbot [NC,OR]
RewriteCond %{HTTP_USER_AGENT} otherbot1 [NC,OR]
RewriteCond %{HTTP_USER_AGENT} otherbot2 [NC]
RewriteRule ^.* - [F,L]

The first rewrite rule (bigbadbot) handles about 100 requests per second, whereas the other two rewrite rules below it only handle a few requests per hour.

My question is, since the first rewrite rule (bigbadbot) handles about 99% of the traffic would it be better to place these rules into two separate rulesets?

For example:

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} bigbadbot [NC]
RewriteRule ^.* - [F,L]

RewriteCond %{HTTP_USER_AGENT} otherbot1 [NC,OR] RewriteCond %{HTTP_USER_AGENT} otherbot2 [NC] RewriteRule ^.* - [F,L]

Can someone tell me what would be better in terms of performance? Has anyone ever benchmarked this?

Thanks!

share|improve this question
add comment

1 Answer

It should have basically no performance difference as once one Cond matches in an OR block, the rest are not processed (there'd be no point). Technically there's a bit of processing done on account of the OR block in the first place, so I suppose breaking it out would be ever so slightly more efficient.

I'd concentrate my efforts elsewhere if you have performance issues. Perhaps profiling whatever application you're serving. Also, if it's hosted, the host might simply have too many websites on the same server.

share|improve this answer
    
I see, so once a match is made it ignores all rewrite rules below it and skips ahead to RewriteRule ^.* - [F,L]? –  Zero Dec 28 '10 at 3:54
    
That's why it's important to order rewrite rules based on the most usage, right? –  Zero Dec 28 '10 at 3:58
    
@Zero, correct. –  Chris S Dec 28 '10 at 13:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.