Forum Moderators: phranque

Message Too Old, No Replies

Remove segments from URL

         

jpatrickm

2:37 am on Nov 26, 2009 (gmt 0)

10+ Year Member



I've gone through as much documentation as I can find but can't seem to get this one working. I feel like the answer is staring me right in the face but I'm missing it.

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!

TheMadScientist

2:43 am on Nov 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi jpatrickm,

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.

jdMorgan

3:38 pm on Nov 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For clarity:

^ = 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

jpatrickm

3:51 am on Nov 28, 2009 (gmt 0)

10+ Year Member



Awesome, that worked perfectly! You saved me lots of frustration on this one.

I appreciate the help very much.
Joe

g1smd

9:45 pm on Nov 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Which of the two URLs do the pages of the site link to?