1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

mod_rewrite help

Discussion in 'PHP & Perl' started by alus1onZ, Jul 27, 2009.

  1. alus1onZ

    alus1onZ Registered Member

    Joined:
    Apr 30, 2009
    Messages:
    63
    Likes Received:
    18
    Hi there! I have a problem with the mod_rewrite that I can't solve, so I'm asking for help.

    I want to make the dinamic urls:

    Code:
    http://domain.com/showcat.php?cat=3D&page=2 
    http://domain.com/showcat.php?cat=3D&subcat=Main&page=2
    
    To look something like this:
    Code:
    http://domain/cat/subcat/page/2/
    http://domain/cat/page/2/
    
    Here is the .htaccess that comes with the script it might help.

    Code:
    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteRule ^top/page/(.*)/$ http://domain.com/top.php?page=$1 [L]
    
    RewriteRule ^latest/page/(.*)/$ http://domain.com/latest.php?page=$1 [L]
    
    RewriteRule ^(.*)/(.*)/(.*).html$ http://domain.com/show.php?cat=$1&sub_cat=$2&img=$3 [L]
    
    RewriteRule ^(.*)/(.*)/$ http://domain.com/showcat.php?cat=$1&subcat=$2 [L]
    
    RewriteRule ^(.*)/$ http://domain.com/showcat.php?cat=$1 [L]
    
    RewriteRule ^most-rated.html$ http://domain.com/showmost.php?type=1 [L]
    RewriteRule ^most-clicked.html$ http://domain.com/showmost.php?type=2 [L]
    RewriteRule ^most-downloaded.html$ http://domain.com/showmost.php?type=3 [L]
    RewriteRule ^most-Searched.html$ http://domain.com/showmost.php?type=4 [L]
    
    Thanks in advance!
     
  2. alus1onZ

    alus1onZ Registered Member

    Joined:
    Apr 30, 2009
    Messages:
    63
    Likes Received:
    18
    Please, someone ... :crazy:
     
  3. lord

    lord Junior Member

    Joined:
    Jan 21, 2009
    Messages:
    176
    Likes Received:
    251
  4. fukinlee

    fukinlee Newbie

    Joined:
    Aug 11, 2009
    Messages:
    22
    Likes Received:
    3
    Lord's example will work, but you should be as specific as possible in your rewrite rules to avoid getting wrong types of data in your PHP scripts. So modify it further to this:

    Code:
    RewriteEngine On
    RewriteRule ^([a-z0-9]+)/([0-9]+)/$ /showcat.php?cat=$1&page=$2 [L]
    RewriteRule ^([a-z0-9]+)/([a-z0-9]+)/([0-9]+)/$ /showcat.php?cat=$1&subcat=$2&page=$3 [L]
    
    This will ensure that $_GET['cat'], $_GET['subcat'], and $_GET['page'] will all contain at least one character, the categories will consist only of lowercase letters and numbers, and your page will only be digits.
     
  5. lord

    lord Junior Member

    Joined:
    Jan 21, 2009
    Messages:
    176
    Likes Received:
    251
    that's a good additon fukinlee :)
     
  6. alus1onZ

    alus1onZ Registered Member

    Joined:
    Apr 30, 2009
    Messages:
    63
    Likes Received:
    18
    Nope, still don't work neither with funinlee's suggestion :(