Forum Moderators: phranque
I have a URL that is in the format:
[domain.com...]
I'm just trying to remove the LC and PROD and replace it with WW.
Here's what I have:
RewriteRule ^LC/PROD(/.*)$ [domain.com...] [R=301,NC]
Sorry if this was posted someplace else but I'm at a loss.
Any help is appreciated!
Welcome to WebmasterWorld!
You're really close...
There are two problems and one edit I see:
1.) You're trying to match a requested location starting with LC/PROD, which is not what the actual location is... ^page/LC/PROD is what you need to match.
2.) By having the / inside the () and then /$1 your will be redirecting to page/WW//category/product when you get a match, so:
RewriteRule ^page/LC/PROD/(.*)$ http://www.example.com/page/WW/$1 [R=301,NC,L]
3.) Nothing to do with the match or the redirected location, but an edit nonetheless, is the addition of the L flag, which indicates Last and should always be used, unless you know you don't need it and why you don't need it...
Just a note if page is a variable, you would want to use:
RewriteRule ^([^/]+)/LC/PROD/(.*)$ http://www.example.com/$1/WW/$2 [R=301,NC,L]
() = Store for Back-Reference
[] = Grouping
^ = Not
/ = What to NOT match
+ = the preceding one or more times
So, the rule says: Match one or more characters not a / followed by /LC/PROD/ followed by anything except the end of a line.
^ = Pattern start anchor -- "Requested URL-path must begin with the following"
() = Store for Back-Reference
[] = Grouping (encloses a list of characters to match)
^ = Not (when used as the first character within a [group], otherwise a literal character)
/ = In this specific case, what to NOT match (we want to quit matching when we find a slash)
+ = Match the preceding character, group, or parenthesized sub-pattern one or more times
. = Any single character (unless escaped with a "\" to match a literal period character)
* = Match the preceding character, group, or parenthesized sub-pattern zero or more times.
$ = Pattern end anchor -- "Requested URL-path must end with the preceding"
Jim