You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Paul Beckett <pa...@outlook.com> on 2013/09/20 15:11:22 UTC

[users@httpd] Relative efficiency of replacing rewrite rules with rewriteMaps

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-urlaRewriteCond ${map-urla:$1}         >""                   [NC]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?

Background:I've just inherited an apache server with about 5000 RewriteRules! The majority of which are currently being evaluated for nearly every request, which I can't imagine is going to be good for performance.A lot of the rewrites are a result of the site owner wishing to ensure original URL's continue to work after the site was restrucutred  (due to external links and associated SEO value of those links).Because page names have been changed, this was done as individual rewrite rules for enormouse numbers of pages.
My initial thoughts were that a rewrite map would be much more efficient. However, because in quite a few cases, it's only the page names that have changed and not the directory name, I'm not sure if this will be more efficient, due to my having to add a RewriteCond to ensure that therewrite rule doesn't create a circular redirect / failure for the new pages (the names of which I often don't know).
Any advice on how this will be evaulated, it's relative efficiency or any better approaches would be greatly appreciated.
Thanks,Paul 		 	   		  

Re: [users@httpd] Relative efficiency of replacing rewrite rules with rewriteMaps

Posted by Eric Covener <co...@gmail.com>.
On Fri, Sep 20, 2013 at 9:11 AM, Paul Beckett <pa...@outlook.com> 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
covener@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org