yet another rewrite question

Discussion in 'Apache' started by Seph, Feb 7, 2007.

  1. #1
    I have just done the unthinkable of changing my urls around so instead of being

    downloads/$category/$item_id/

    it is now

    /$category/$item_name/

    so I suppose I need a regex which will take the category variable and 301 it to the new location, and if the item id is available then 301 it to the category since the item id can't be translated to item name.

    So I'm thinking I probably need two rules

    So it's something like this to do the redirect for categories

    RewriteRule ^/downloads/(.*)/$ /$1/ [R=301,L]

    and this for item id's

    RewriteRule ^/downloads/(.*)/([0-9]+)/$ /$1/ [R=301,L]

    this is my first rewrite rule though, so I'd rather have it checked then just put it to use and have it fail. :)

    Also is it possible to take a part of the url and make it upper case? Say the category name?
     
    Seph, Feb 7, 2007 IP
  2. Pat Gael

    Pat Gael Banned

    Messages:
    1,331
    Likes Received:
    68
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I gues you will need to wait for Nintendo to answer your question, unless another DP member with good rewrite knowledge comes first.
     
    Pat Gael, Feb 7, 2007 IP
  3. moneyspeaks

    moneyspeaks Peon

    Messages:
    450
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you are making your life so difficult with this url, no?
     
    moneyspeaks, Feb 7, 2007 IP
  4. Seph

    Seph Peon

    Messages:
    84
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    well it should be simple enough, it's just extracting one variable from the url and then using it in the url to redirect to.
     
    Seph, Feb 7, 2007 IP
  5. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #5
    er why did you change it when it wasn't very broken!!!!!! Oh I hope you don't have pages already indexed in the search engines!!!!

    RewriteRule ^downloads/(.*)/(.*)$ http://www.domain.com/$1 [R=301,L]
     
    Nintendo, Feb 7, 2007 IP
  6. Seph

    Seph Peon

    Messages:
    84
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I basically only want to get rid of downloads yeah, I know I can't redirect every single page to it's new destination, already specified that, however, I can redirect them all to their category index, which will do just fine.

    And it was sorta broken, /category/1231/ isn't very descriptive, the item name is far more descriptive, and only a few of the items are actually indexed so it shouldn't hurt too much.

    But would my regexes work for getting rid of the /downloads/ part and the /$item_id/ part?
     
    Seph, Feb 7, 2007 IP
  7. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #7
    You need the complete domain in the code, like in my last post.
     
    Nintendo, Feb 7, 2007 IP
  8. Seph

    Seph Peon

    Messages:
    84
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Awesome thanks, what about extracting part of the url and making it upper case? Is .htaccess capable of that?
     
    Seph, Feb 7, 2007 IP
  9. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #9
    RewriteEngine on
    RewriteMap upper2lower int:tolower
    RewriteRule ^/(.*)$ /${upper2lower:$1}

    is the other way around. I'm not sure if there is a lower to upper.
     
    Nintendo, Feb 7, 2007 IP