tags:

views:

36

answers:

3

Since adding this basic .htaccess to my index directory, each page load slows down by maybe 20-30 seconds:

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^(.+)-(.+) movie.php?id=$1 [NC]

Is there some malformation or bad regex formatting here? I can't see anything wrong with it.

Thanks!

As an update, just these 2 lines are enough to put the slow down on:

Options +FollowSymlinks
RewriteEngine on
A: 

Even though I think that 20-30 seconds is a little bit far-fetched, here some concerns about your current regex:

  • Part of your regex isn't required, so drop it. Especially if this part already looks like a lot of backtracking (and (.+) does). Thus you may reduce the regex to ^(.+)-.
  • You are matching an ID with (.+). That isn't the optimal approach. Better use ([^-]+) instead. This will mach any char that isn't an - (and that's what you want.)

The resulting Rule thus is:

RewriteRule ^([^-]+)- movie.php?id=$1 [NC]

Even better (this allows only integral IDs):

RewriteRule ^([0-9]+)- movie.php?id=$1 [NC]
nikic
Thanks, but it doesn't seem to have sped it up though. Is it possible it's a server config problem?
James
Probably. 20-30 seconds is way to slow, even for your regex ;)
nikic
Right, I'll have to investigate further then. Thanks for the regex tips, I'll bear them in mind and change my current ones.
James
A: 

It looks like you're running requests through your movie script. So how long does it take your movie.php script to run? If it takes 20-30 seconds, well, then there you go!

Chris Thornton
The rule just redirects pages which meet that criteria to movie.php, which loads instantly anyway, so I can't see that as the problem really?
James
It would be a problem if movie.php ran for 30 seconds. Since it doesn't, that's not the problem.
Chris Thornton
A: 

Turn on rewrite logging and crank the level up, see what your RewriteRule is doing:

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritelog
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteloglevel

If the regex is having to work overtime, you'll quickly see Apache's error log explode in size, especially at the higher levels of rewrite logging.

Marc B