mod rewrite help

Discussion in 'PHP' started by baris22, Jan 24, 2008.

  1. #1
    Hello,

    I have got a url like

    this is the first page of url
    category.php?cat=movie
    PHP:
    second page is

    category.php?cat=movie&page=2&sortby=
    PHP:
    if i sort it by date it goes like

    
    category.php?cat=movie&page=2&sortby=date
    
    PHP:
    I could not figure it out how to do the rewrite.

    I managed make one for the first page

    
    RewriteRule ^category-(.*)$ category.php?cat=$1 [L,NC]
    
    PHP:
    but i did not know what to do for the other pages.

    Thank you for your help.
     
    baris22, Jan 24, 2008 IP
  2. ilovelinux

    ilovelinux Peon

    Messages:
    285
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I suggest you use friendly permalinks. SEO friendly :)
     
    ilovelinux, Jan 24, 2008 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    ^ Genius reply. :) That's exactly what he's having problems with.

    Can you post an example of how you want the rewritten URLs to look like?
     
    nico_swd, Jan 25, 2008 IP
    baris22 likes this.
  4. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #4
    1st Page
    category.php?cat=movie => category-movie.html
    RewriteRule ^category-(.*)\.html$ category.php?cat=$1 [L,NC]

    2nd Page
    category.php?cat=movie&page=2&sortby= => category-movie-page-2.html
    RewriteRule ^category-(.*)-page-([0-9]+)\.html$ category.php?cat=$1&page=$2&sortby= [L,NC]

    3rd Page
    category.php?cat=movie&page=2&sortby=date => category-movie-page-2-sortby-date.html
    RewriteRule ^category-(.*)-page-([0-9]+)-sortby-date\.html$ category.php?cat=$1&page=$2&sortby=date [L,NC]
     
    Kaizoku, Jan 25, 2008 IP
  5. ilovelinux

    ilovelinux Peon

    Messages:
    285
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for the complement!
     
    ilovelinux, Jan 25, 2008 IP
  6. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #6
    No luck. it is not working.

    I am using

    
    RewriteRule ^category-(.*)$ category.php?cat=$1 [L,NC]
    RewriteRule ^category-(.*)-([0-9]+)$ category.php?cat=$1&page=$2 [L,NC]
    RewriteRule ^category-(.*)-([0-9]+)-(.*)$ category.php?cat=$1&page=$2&sortby=$3 [L,NC]
    
    PHP:
    this is my code
    
    "<a href=\"category-".$cat_name."-".$next_page."-".$sortby."\">Next ".$limit." videos &raquo;</a>" 
    
    PHP:
    any idea why it is not working?

    this one works for the first page
    
    RewriteRule ^category-(.*)$ category.php?cat=$1 [L,NC]
    
    PHP:
     
    baris22, Jan 25, 2008 IP
  7. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #7
    Ok. sorted.

    I just changed the order

    
    RewriteRule ^category-(.*)-([0-9]+)-(.*)$ category.php?cat=$1&page=$2&sortby=$3 [L,NC]
    
    RewriteRule ^category-(.*)-([0-9]+)$ category.php?cat=$1&page=$2 [L,NC]
    
    RewriteRule ^category-(.*)$ category.php?cat=$1 [L,NC]
    
    PHP:
     
    baris22, Jan 25, 2008 IP