httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Covener <>
Subject Re: [users@httpd] Relative efficiency of replacing rewrite rules with rewriteMaps
Date Fri, 20 Sep 2013 14:04:13 GMT
On Fri, Sep 20, 2013 at 9:11 AM, Paul Beckett <> wrote:
> I would like to try and reduce the number of rewrite rules I have (from
> 5000) to a much smaller number of rewrite maps. My main goals in doing this
> are to improve site performance, and make configuration more manageable.
> I need to be able to handle the following cases:
> /dir1/link1    -> /dir1/other1
> /dir1/link2    -> /dir1/random2
> /dir1/link3    -> /dir1/link3    [no change, and I don't know all the
> possible URL's]
> /dir2/link4    -> /dir3/link5
> The best I've been able to come up with in the Apache config is:
> RewriteMap  map-urla               txt:/path/to/map-urla
> RewriteCond ${map-urla:$1}         >""                   [NC]

If you used a regex in the 2nd parm, you could capture the map lookup
here and not run it again for substitution. Probably faster then the
cached lookup from the map.

> RewriteRule ^/dir1/map-urla(.*)$   /dir1/${map-urla:$1}  [R]

> This works in terms of getting URL's to the write place, but before I expend
> a colossal amount of effort rewriting over 5000 lines of config, I'm hoping
> to clarify that this will actually provide a performance benefit.
> In particular, will it only evaluate the /dir1/ path once, and skip over
> this for other urls (eg. /dir2/) or will the rewriteCond be evaluated first
> going through every line in the rewritemap prior to evaluating the /dir1?

Rewriterule evaluated, but not substituted, first. That is where you
want to discriminate the most, not in the conditions, even though it's
tempting to do that.

You'll probably have to simulate it before really porting the 5000
rules to get a feel if it's only academically better/worse.  But at
5000 rules, if 'L' is not used and carefully ordered it should help.

Eric Covener

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message