Mod Rewrite 301 Help

Discussion in 'Site & Server Administration' started by cesarcesar, May 6, 2011.

  1. #1
    I need to 301 some links. I have been getting my knees wet with ModRewrite for a while now, but this one seems to throw me. The format I'm looking for is below.

    Old - http://www.sitename.com/big-widget/blue/2.html

    New - http://www.sitename/blue-big-widgets/2.html

    Two thinks to note, I have added a (s) to the end of widgets. As well as the 2.html will be any number between 1-100 depending on the page.

    Thanks for your help in figuring this out.
     
    cesarcesar, May 6, 2011 IP
  2. strudinox

    strudinox Active Member

    Messages:
    84
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    76
    #2
    I think all you would need is:

    Redirect 301 /big-widget/blue/ http://www.sitename/blue-big-widgets/
    Code (markup):
    Just throw that in a .htaccess inside the /blue/ directory and you should be good. I've had to do this once before as well.
     
    strudinox, May 7, 2011 IP
  3. cesarcesar

    cesarcesar Peon

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the suggestion. The solution I ended up going with was

    RewriteRule ^(big-widget)/([^/\.]+)/(.*) $2-$1es/$3 [R=301,L]
    Code (markup):
    A more dynamic version is

    RewriteRule ^([^/\.]+)/([^/\.]+)/(.*) $2-$1es/$3 [R=301,L]
    Code (markup):
     
    cesarcesar, May 9, 2011 IP