lucy24 - 12:28 am on Feb 19, 2013 (gmt 0)
Since when does mod_rewrite support \d\d captures? I thought they cut out at nine :(
Picking one rule at random and getting rid of the unneeded escapes:
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([0-9]+)_([^/]*)/$ /view_profile.php?id=$4 [QSA,L]
What's the QSA for? Surely the point of those long URLs is that there is no query string; it's all in the body of the URL.
is bad because it allows malformed requests with two or more consecutive // --and your code would interpret them as null directories, which I'm sure is not what you want. Always use
Now, if you're not reusing the first three groups, why capture them at all? In some cases you may need the parentheses for grouping; you can then mark them as (?:blahblah) for non-capturing. Here you don't need the parentheses at all:
^[^/]+/[^/]+/[^/]+/([0-9]+)_[^/]+/$ /view_profile.php?id=$1 [L]
But that leaves a bigger problem. The version with query string and the version without query string have to be deducible from each other within mod_rewrite. Any time you have a rule expressed as
RewriteRule aaa bbb [L]
there has to be a preceding rule in the form
RewriteRule bbb aaa [R=301,L]
If aaa and bbb aren't each deducible from the other, you're in php-script territory.