Forum Moderators: phranque

Message Too Old, No Replies

Effect of numerous redirects rules on speed

         

agneslesage

7:43 am on Aug 31, 2010 (gmt 0)

10+ Year Member



Hello

I ve had a change of site (from asp to php) resulting in a number of 301 redirect rules in .htaccess, of type:

RewriteCond %{QUERY_STRING} ^([^&]*&)*page=qui_nous(&.*)?$
RewriteRule ^template\.asp$ http://www.atable.com/qui-sommes-nous/? [R=301,L]


And then I am using e-commerce plugin with postname-type URL, which unfortunately does not allow to keep permalinks, so whenever a product name change I am adding another redirect like:

RewriteRule traiteur/buffets-et-cocktails/buffets/buffet-sandwich-tarte-salade-froid http://www.atable.com/traiteur/buffets-et-cocktails/buffets/formule-tarte-salade/ [R=301,L]


With the precious help of Jim on [webmasterworld.com...]

Now, I start wondering, if I multiply these rules (I already have some 60 above my other WP rules), is it not going to seriouslt slow down the access to the web site?

Thanks
Agnes

jdMorgan

1:18 pm on Aug 31, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Adding 60 rules might introduce a noticeable delay on a busy site on a shared server.

But you don't need 60 rules, you can do it with just one:

# Externally redirect old catering URLs to new URLs, using a lookup-table method
# Template: RewriteCond $1>New-URL-path ^Old-URL-path><generic-pattern-to-capture-New-URL-path>$
RewriteCond $1>buffets-et-cocktails/buffets/formule-tarte-salade/ ^buffets-et-cocktails/buffets/buffet-sandwich-tarte-salade-froid>(.+)$ [OR]
RewriteCond $1>buffets-et-cocktails/buffets/formule-gateau-salade/ ^buffets-et-cocktails/buffets/buffet-sandwich-gateau-salade-froid>(.+)$ [OR]
...
RewriteCond $1>buffets-et-cocktails/buffets/formule-mousse-au-chocoalat-salade/ ^buffets-et-cocktails/buffets/buffet-sandwich-mousse-au-chocoalat-salade-froid>(.+)$
RewriteRule ^traiteur/(.+)$ http://http://www.atable.com/traiteur/%1 [R=301,L]

Here, we pass only the changing part of the requested URL-path to the RewriteConds (as $1). The RewriteConds are then used to check that path, and if a match is found then we know that we have an "old" URL, so we capture the corresponding "new" URL into %1. The RewriteRule then substitutes this new path into the URL and redirects to the new URL.

None of the RewriteConds will be processed unless the RewriteRule pattern matches first.

Et voila, une seule RewriteRule.

Take full advantage of the fact that RewriteConds can back-reference RewriteRule pattern matches, and RewriteRules can back-reference RewriteCond pattern matches.

Note that the above approach is "a little complicated." It is "visually-confusing," and can be error-prone until you get used to it. For that reason, I suggest using this method only when the old URLs are similar to each other and you need more than six rules to do it "the simple way." I would guess that given average-length URL-paths, the simple approach would be faster than using this lookup-table method for less than six URLs.

Jim

agneslesage

2:09 pm on Aug 31, 2010 (gmt 0)

10+ Year Member



oulala... I do note that it is "a little bit complicate!"

Now I think I'll need give you more examples of the "60 rules" pattern if you are to help me simplify, because I wont decline it myself.

I am still to change these URL (the whole catering calaog actually... very appetizing), so let us see then...

Thanks
Agnes