mod_rewrite not working with page.php?id=3&page=2

Discussion in 'Apache' started by anversli, Jan 19, 2007.

  1. #1
    Hi,

    I'm using the mod_rewrite function to have friendly URL's, but now i'm facing a little problem and i can't solve it.

    My .htaccess file:
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    
    RewriteRule ^game\-([0-9]*)\-(.*)\.html game.php?id=$1 [L]
    RewriteRule ^cat\-([0-9]*)\-(.*)\.html  cat.php?id=$1 [L]
    RewriteRule ^cat\-([0-9]*)\-(.*)\-(.*)\.html cat.php?id=$1&page=$2 [L]
    RewriteRule index\-(.*)\.html$ index.php?page=$1 [L]
    Code (markup):
    Everything is working well exept ths one:
    RewriteRule ^cat\-([0-9]*)\-(.*)\-(.*)\.html cat.php?id=$1&page=$2 [L]
    Code (markup):
    The dynamic url's of my category page is like:
    cat.php?id=1 and i'm rewriting to cat-catid-cattitle.html, this is ok.

    Now, i'm using pagination script for my category pages and the dynamic url's are like: cat.php?id=1&page2,3,4... but i wanna rewrite this to cat-catid-cattitle-2.html, cat-catid-cattitle-3.html, cat-catid-cattitle-4.html and...

    Who can help me to fix this problem.
     
    anversli, Jan 19, 2007 IP
  2. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #2
    Change

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

    to

    RewriteRule ^cat\-([0-9]*)\-(.*)\-(.*)\.html cat.php?id=$1&page=$2 [L]
    RewriteRule ^cat\-([0-9]*)\-(.*)\.html cat.php?id=$1 [L]
     
    Nintendo, Jan 19, 2007 IP
  3. anversli

    anversli Active Member

    Messages:
    350
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #3
    Hi Nintendo

    I got this error:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-10, 10' at line 1
     
    anversli, Jan 19, 2007 IP
  4. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #4
    Is their a reason you have an extra (.*)? That looks like a mySQL error, not a mod_rewrite error.

    Try it with just the

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

    taken out. It might be the script trying to make the extra (.*), if it is doing something for that part of the URL.
     
    Nintendo, Jan 19, 2007 IP
  5. anversli

    anversli Active Member

    Messages:
    350
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #5
    anversli, Jan 19, 2007 IP
  6. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #6
    Nintendo, Jan 19, 2007 IP
  7. anversli

    anversli Active Member

    Messages:
    350
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #7
    Yes the title is listed as second and its generated by this code

    RewriteRule ^cat\-([0-9]*)\-(.*)\-(.*)\.html cat.php?id=$1&page=$3 [L]
    This is still not working, when i click next page the games are not changing.
     
    anversli, Jan 19, 2007 IP
  8. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #8
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^cat\-([0-9]*)\-([^.]+)\-([^.]+)\.html$ cat.php?id=$1&page=$2 [L]
    RewriteRule ^cat\-([0-9]*)\-([^.]+)\.html$ cat.php?id=$1 [L]
    RewriteRule ^game\-([0-9]*)\-([^.]+)\.html$ game.php?id=$1 [L]
    RewriteRule index\-([^.]+)\.html$ index.php?page=$1 [L]

    and then empty your browser cache.
     
    Nintendo, Jan 19, 2007 IP
    Colleen likes this.
  9. anversli

    anversli Active Member

    Messages:
    350
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #9
    anversli, Jan 19, 2007 IP
  10. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #10
    Try

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^cat\-([^.]+)\-([^.]+)\-([^.]+)\.html$ cat.php?id=$1&page=$3 [L]
    RewriteRule ^cat\-([^.]+)\-([^.]+)\.html$ cat.php?id=$1 [L]
    RewriteRule ^game\-([^.]+)\-([^.]+)\.html$ game.php?id=$1 [L]
    RewriteRule ^index\-([^.]+)\.html$ index.php?page=$1 [L]

    with a deleted cache, and is their any other .htaccess code?
     
    Nintendo, Jan 19, 2007 IP
  11. anversli

    anversli Active Member

    Messages:
    350
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #11
    Nintendo, this one is working but there is a small problem.

    When i click on a category page from the home page like, http://www.game-console.nl/cat-18-Funny-Games.html i'm getting a mysql error:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-10, 10' at line 1
    Code (markup):
    But when i click on the category page itself for next pages it works but also with a smal problem. When i click on the 4th page i got this url http://www.game-console.nl/cat-18-Funny-Funny-Funny-Funny-Games-4.html

    Here's the full htaccess code, there is also anti hotlinking

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^cat\-([^.]+)\-([^.]+)\-([^.]+)\.html$ cat.php?id=$1&page=$3 [L]
    RewriteRule ^cat\-([^.]+)\-([^.]+)\.html$ cat.php?id=$1 [L]
    RewriteRule ^game\-([^.]+)\-([^.]+)\.html$ game.php?id=$1 [L]
    RewriteRule ^index\-([^.]+)\.html$ index.php?page=$1 [L]
    
    
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?game-console.nl [NC]
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?uwspelletjes.nl [NC]
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?minispel.be [NC]
    RewriteRule \.(swf|dcr)$ http://www.game-console.nl/500.html [NC,R,L]
    Code (markup):
     
    anversli, Jan 20, 2007 IP
  12. anversli

    anversli Active Member

    Messages:
    350
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #12
    Nintendo,
    Tnx for your help, did some changes on the script and its working now.

    Changed my htaccess file to:
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^cat-([0-9]*)-(.*)-(.*).html$ cat.php?id=$1&page=$3 [L]
    RewriteRule ^cat-([0-9]*)-(.*).html$  cat.php?id=$1 [L]
    RewriteRule ^game-([0-9]*)-(.*).html$ game.php?id=$1 [L]
    RewriteRule index-(.*)\.html$ index.php?page=$1 [L]
    
    
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?game-console.nl [NC]
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?uwspelletjes.nl [NC]
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?minispel.be [NC]
    RewriteRule \.(swf|dcr)$ http://www.game-console.nl/500.html [NC,R,L]
    Code (markup):
    When someone goes to /cat-3-sportgames.html it gives a mysql error, but all pages with /cat-3-sportgames-1.html, /cat-3-sportgames-2.html... are working perfect. I've changed all category links on the homepage to, /cat-3-sportgames-1.html and its working now.

    Thx again Nintendo.
     
    anversli, Jan 20, 2007 IP
  13. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #13
    Nintendo, Jan 20, 2007 IP
  14. anversli

    anversli Active Member

    Messages:
    350
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #14
    Yes, they are the same.
    The first one without friendly urls is working, but the second one is not working.

    I cant find anything on the script.
     
    anversli, Jan 20, 2007 IP
  15. anversli

    anversli Active Member

    Messages:
    350
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #15
    Nintendo, this is the part for pagination.
    echo '<div class="pages pkg"><div class="paginator">';
    if ($begin > 1) {	
    			$cat_sql = "SELECT * FROM `game_cat` WHERE cat_ID = '".$_GET['id']."'";
    			$query = mysql_query($cat_sql) or die(mysql_error());
    			while ($cat_data = mysql_fetch_assoc($query))
    			
    			$titel = str_replace(" ","-",$cat_data['cat']);
        		echo'<a href="cat-'.$_GET['id'].'-'.$titel.'-1.html" title="Eerste pagina">&laquo; eerste]</a> <a href="cat-"'.$cat_data['cat_ID'].'"-"'.$titel.'"-'.$vorige.'.html" title="Vorige Pagina">&lt;</a> ';
    }
    for ($i = $begin; $i <= $end; $i++) {
        if ($i == $page) {
                echo '<b>..'.$page.'..</b>';
        }
        else {	$cat_sql = "SELECT * FROM `game_cat` WHERE cat_ID = '".$_GET['id']."'";
    			$query3 = mysql_query($cat_sql) or die(mysql_error());
    			while ($cat_data = mysql_fetch_assoc($query3))
                $titel = str_replace(" ","-",$cat_data['cat']);
                echo '<a href="cat-'.$_GET['id'].'-'.$titel.'-'.$i.'.html"> '.$i.' </a>';
        }
    }
    if ($end < $num_pages) { 
    			$cat_sql = "SELECT * FROM `game_cat` WHERE cat_ID = '".$_GET['id']."'";
    			$query4 = mysql_query($cat_sql) or die(mysql_error());
    			while ($cat_data = mysql_fetch_assoc($query4))
        		echo '&nbsp;<a href="cat-'.$_GET['id'].'-'.$titel.'-'.$volgende.'.html" title="Volgende Pagina">&gt;</a>  <a href="cat-'.$cat_data['cat_ID'].'-'.$titel.'-'.$num_pages.'.html" title="Laatste Pagina">laatste &raquo;</a>';
    }
    PHP:
     
    anversli, Jan 20, 2007 IP
  16. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #16
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^cat\-([0-9]*)\-(.*)\-(.*)\.html$ cat.php?id=$1&page=$3 [L]
    RewriteRule ^cat\-([0-9]*)\-(.*)\.html$ cat.php?id=$1 [L]
    RewriteRule ^game\-([0-9]*)\-(.*)\.html$ game.php?id=$1 [L]
    RewriteRule index\-(.*)\.html$ index.php?page=$1 [L]


    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?game-console.nl [NC]
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?uwspelletjes.nl [NC]
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?minispel.be [NC]
    RewriteRule \.(swf|dcr)$ http://www.game-console.nl/500.html [NC,R,L]

    with the cache empty.

    It might be the - from Funny-Games driving mySQL bonkers. Changing - to _ would be one other idea.
     
    Nintendo, Jan 20, 2007 IP
  17. anversli

    anversli Active Member

    Messages:
    350
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #17
    anversli, Jan 21, 2007 IP