Forum Moderators: phranque
Example:
abc_foo-v0.2.1.php -> abc_foo.php
abc_foo_bar-v0.1.php -> abc_foo_bar.php
The naming convention is fairly straightforward. There is either one or two [a-z] name modifiers after the initial 'abc' prefix. The version number is always pretty much v0.x or v0.x.x
Here is the rule I have so far:
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^/sandbox/plugins/(abc_[a-z]+)(_[a-z]+)?(\-v0\.[0-9]+)(\.[0-9])?\.php$ /sandbox/plugins/$1$2.php [R=301,L] However, as of yet the redirect isn't working. I know it's close... any ideas?
If I am understanding correctly, it looks like you should be able to accomplish your goal with a forward looking negative regular expression. This should be more efficient than trying to find a specific match, because we can 'look ahead' and break when there is not a match, like this:
RewriteRule ^sandbox/plugins/([^-]+)[-]v /sandbox/plugins/$1.php [R=301,L]
By changing to the forward looking expression, we can store anything that is not a - in a variable, then by requiring the -v for a match, we can eliminate looping of your new file (the v appears to be overkill, but if any of the files are - something-else may be required). Normally, I recommend a hard ending ($) on the left side of the rule, but in this case, leaving it off allows us to use the implicit 'and anything else' so we do not have to check for an exact match, because if we match this far, the information need is already stored, and files that should not be rewritten (should) have been eliminated by not matching the -v pattern.
Hope this helps.
Justin
Added: [] on the - are really optional, I use them to keep things straight in my head sometimes =)