Dideved - 12:56 am on Aug 24, 2013 (gmt 0)
It looks like you're trying to write using a globbing [en.wikipedia.org] style of pattern matching. But Apache uses a Perl-compatible regular expression style of pattern matching. In globbing, I think the * means any filename or directory. The equivalent regular expression would be:
This means one or more non-slash characters. So now your pattern looks like this:
The period has special meaning in regular expressions, so we should escape it with a backslash in order to match a literal period.
We also need to use start- and end-of-string anchors. Right now, this URL pattern we're matching could appear somewhere in the middle of a much larger string that we don't want to match. We need to make sure that our pattern can only start matching right at the beginning of the string and can only stop matching at the end.
And finally, we need to "remember" the portion of the URL up to the -sales part. In regular expressions, we use "capturing parentheses."
Now that portion will be available as the variable $1 when we form the replacement URL.
(Note that if we use the redirect directive, then we need to match the initial slash in the path, but if we use a rewrite directive, then in most cases, we must not match the leading slash. In this case, it's probably best to switch to to a rewrite rule.)
Here's the finished product:
RewriteRule ^([^/]+/[^/]+/[^/]+)-sales\.php$ $1.php [R=302,L]
Switch the R=302 to R=301 whenever you feel comfortable.