Forum Moderators: phranque
mod_rewrite is much more efficient than PHP or any other non-native 'language' so let that be your guide.
My "average site" has anywhere between two dozen and three hundred rules on it, with no visible impact on performance with 10,000 to 100,000 hits and mostly fairly-decent-but-shared virtual servers. But I try to write very tight code using very-efficient patterns.
Jim
Using the wild-card multiple times in one pattern is the biggest problem -- character classes not so much.
A really bad way to do a pattern is something like:
^(.*)/(.*)/(.*)$
Remember, ".*" is both ambiguous and 'greedy' -- On the first matching attempt, the pattern-matcher will try to put the entire input string into the first ".*" and fail because the rest of the pattern is left 'starved'. So it will move one character from the end of the string and try to match the rest into the first ".*" again. This will again fail, so it will move one more character from the end of the string and try to match the rest into the first ".*" yet again. This will repeat until the input string is apportioned sufficiently for all of the subpatterns to match.
A better way to code the above pattern is:
^([^/]+)/([^/]+)/([^/]*)$
^([^/]+)/([^/]+)/(.*)$
^(([^/]+/)+)([^/]+)/([^/]*)$
All of these are negative-match patterns, and allow a single left-to-right matching attempt to determine a match or no match. Note that you might have to do a bit of clean-up on the $1 back-reference in the last rule; It would contain a possibly-unwanted trailing slash.
You can avoid the redundant character-class [A-Za-z] by using the [NC] flag on RewriteRules and RewriteConds to make the compare case-insensitive, and then specifying only [a-z] or [A-Z].
Jim