Forum Moderators: phranque
RewriteRule ^static_url-(91).asp /article.php?spt_id=$1 [L]
and it works fine and dandy but I'm looking for a sulution where I don't have to add a new rule for every URL that I want rewritten because the bit at the end of the URL (in this case 91.asp) is the only significant part.
Ideally what I need some help with is a rewrite rule that does this:
RewriteRule ^any_old_stuff_here-(number).asp
/article.php?spt_id=number [L]
I'm sure it's easy but I can't figure it out - any help would be much appreciated.
Don't use ".*" if you can avoid it. The reason is that ".*" is the least-specific pattern possible, and it causes extra work. Looking at this code, here's what happens:
RewriteRule ^.*-(.*).asp /article.php?spt_id=$1 [L]
Here's an alternate way to do the same thing that does not involve so much work:
RewriteRule ^[^-]+-([^.]+).asp$ /article.php?spt_id=$1 [L]
This requires one or more characters not equal to a hyphen, followed by a hyphen, then one or more characters not equal to a period, followed by ".asp". It can be processed entirely in a forward direction with no ambiguity and no repeated "cut and try".
".*" is easy to write, and somewhat familiar, but horribly inefficient. On a busy site with a lot of RewriteRules, it can make or break your server's performance. The same is true in scripting languages that support regular expressions.
Jim
If anything's not clear, post! This forum is supposed to be a place to discuss techniques, although it does seem more like a "mod_rewrite repair shop" most of the time.
Jim