Apache: Slow rewrite rule

One online shop at work saw a drastic performance loss after upgrading: Even accessing static .js files took at least 0.7 seconds.

Upon debugging we saw that the slowness went away when we disabled Apache's RewriteEngine. That led us to inspect each RewriteRule, and in the end we found that this one was the troublemaker:

RewriteRule  ^(.*)/(.*){1,15}/(.*)\.html$  http://../$2 [R=301,L]

The second * is the culprit here; it's not needed for the intended function and makes the regex the slower the longer the input URL is.

The totally correct rule would have been:

RewriteRule  ^[^/]+/[^/]{1,15}/[^/]+\.html$  http://../$2 [R=301,L]

Written by Christian Weiske.

Comments? Please send an e-mail.