1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Regular expression help

Discussion in 'Apache' started by dpmis, Oct 23, 2005.

  1. #1
    Hi :)

    I have a regex problem with mod_rewrite.

    Here's what I'm trying to do:

    Convert this:

    www.site.com/home/cooking/asian

    to index.php?cat=asian

    Seems simple. But I need something that can work with infinate categories. The regex just needs to find the last category name and tap that on the end of index.php?cat=

    For example it could be sites.com/computers/internet/design/photoshop or just site.com/computers.

    My current rule is:
    RewriteRule ^(.*)/$ index.php?cat=$1 [QSA,L]

    But that only works for a URL like this:

    site.com/computers/

    It doesnt work on 2nd, 3rd teir categories etc.

    Can anyone help me out with this rule? Cheers :D :D
     
    dpmis, Oct 23, 2005 IP
  2. Dejavu

    Dejavu Peon

    Messages:
    916
    Likes Received:
    53
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That should work with 3 sublevels, easy to expand to more. If you truly want infinite subcats, it might be more difficult..
     
    Dejavu, Oct 23, 2005 IP
  3. dpmis

    dpmis Peon

    Messages:
    60
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Cheers!

    Yeah that will do it. I just expended it a few more dirs just to make sure :)
     
    dpmis, Oct 23, 2005 IP