Conditional mod rewrite

Discussion in 'Apache' started by lektrikpuke, Jun 28, 2009.

  1. #1
    I currently have a rewrite rule:

    RewriteRule ^folder_name/([^/]*)-([^/]*)\.html$ /cat-page.php?ccat=$1&page=$2 [L]

    This works great for pages 2 and up. Actually, it works with page 1 too, but you have to put page 1, which I don't want to do.

    Is there a way to get a conditional rewrite that will ignore page if it's 1? Or page = 1 if there is no page?

    Thanks for any help. :)
     
    lektrikpuke, Jun 28, 2009 IP
  2. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #2
    Figured it out on my own, and am posting the solution (however inelegant it may be) just in case it may help someone else some day.

    Had to write 3 rules and they have to be in this order:

    RewriteRule ^folder_name/([^/]*)-([0-9][0-9])\.html$ /cat-page.php?ccat=$1&page=$2 [L]
    RewriteRule ^folder_name/([^/]*)-([2-9])\.html$ /cat-page.php?ccat=$1&page=$2 [L]
    RewriteRule ^folder_name/([^/]*)\.html$ /cat-page.php?ccat=$1 [L]

    The first rule checks for pages greater than or equal to 10 (0-9 0-9).
    Second checks for pages between 2 and 9 inclusive (2-9).
    Third checks for pages without a page number.

    Rob :D
     
    lektrikpuke, Jun 29, 2009 IP