mod_rewrite question

Discussion in 'Directories' started by stephaneggy, Dec 17, 2004.

  1. #1
    Hello! I use the free directory script and want to do the mod_rewrite, i saw this page: http://mod-rewrite.com/forum/thread45.html

    I want to do the mod rewrite tric kto my directory as well but I don't have the things he is saying there like:
    Basically every occurrance of
    Code:
    <A HREF="'.$dir.'index.php?c='.$subcategories[$x]["id"].'">

    replace with

    Code:
    <A HREF="'.$dir.''.$subcategories[$x]["id"].'.html">

    But I don't have <A HREF="'.$dir.'index.php?c='.$subcategories[$x]["id"].'">

    Maybe i got a new version of the script or so?
    I also saw this page:
    http://translate.google.com/translate?u=http://www.modrewrite.de/tutorial_03.html

    Here it says replace:
    LINE # 66: < DIV $CLcAcScS="logo"><cA HREF="<? echo $$dir?>index.php"></a></div >

    But Again, I don't have that.
    Can someone help me with my mod_Rewrite, where must I place wich code? This is my index.php file:

    <?
    require_once("config.php");
    require_once("include.php");
    require_once("template_index.php");
    $c *= 1;
    if ($c == 0) $c = 1;
    $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password);
    mysql_select_db($mysql_database, $bd);
    $sql = mysql_query("SELECT name, title, description, pages, ref FROM {$prefix}categories WHERE id = $c");
    $current_category = mysql_fetch_array($sql, MYSQL_ASSOC);
    if (($c > 1) & !$current_category["name"]){
    mysql_close();
    header("Location: {$dir}");
    exit();
    };
    if (!$current_category["name"]) $current_category["name"] = "Free PHP Directory Script";
    if (!$current_category["description"]) $current_category["description"] = $current_category["name"]." ".$current_category["title"];
    $replace = array("[CATEGORY_NAME]" => $current_category["name"], "[CATEGORY_TITLE]" => $current_category["title"], "[CATEGORY_DESCRIPTION]" => $current_category["description"]);
    echo strtr($TEMPLATE["HEADING"],$replace);
    flush();
    $last_category = false;
    $ref = $c;
    while(!$last_category){
    $n_parent_categories += 1;
    $sql = mysql_query("SELECT id, name, ref FROM {$prefix}categories WHERE id = $ref");
    $parent_categories[$n_parent_categories-1] = mysql_fetch_array($sql, MYSQL_ASSOC);
    if ($parent_categories[$n_parent_categories-1]["ref"] == 0){
    $last_category = true;
    }else{
    $ref = $parent_categories[$n_parent_categories-1]["ref"];
    };
    };
    echo $TEMPLATE["PATH"]["HEADING"];
    for ($x = $n_parent_categories-1; $x >= 0; $x--){
    if ($x != $n_parent_categories-1) echo $TEMPLATE["PATH"]["SEPARATOR"];
    if ($x == 0){
    $replace = array("[CATEGORY_NAME]" => $parent_categories[$x]["name"]);
    echo strtr($TEMPLATE["PATH"]["CURRENT_CATEGORY"],$replace);
    }else{
    if ($parent_categories[$x]["id"] > 1){
    $category_url = $dir.'index.php?c='.$parent_categories[$x]["id"];
    }else{
    $category_url = $dir;
    };
    $replace = array("[CATEGORY_NAME]" => $parent_categories[$x]["name"], "[CATEGORY_URL]" => $category_url);
    echo strtr($TEMPLATE["PATH"]["CATEGORY"],$replace);
    };
    };
    echo $TEMPLATE["PATH"]["FOOTER"];
    flush();
    $sql = mysql_query("SELECT {$prefix}categories.id, {$prefix}categories.name FROM {$prefix}categories LEFT JOIN {$prefix}pages ON {$prefix}pages.category = {$prefix}categories.id AND {$prefix}pages.accepted = 'y' WHERE ref = $c GROUP BY {$prefix}categories.id ORDER BY {$prefix}categories.name");
    $n_subcategories = mysql_num_rows($sql);
    for ($x = 0; $x < $n_subcategories; $x++){
    $subcategories[$x] = mysql_fetch_array($sql, MYSQL_ASSOC);
    };
    if ($n_subcategories > 0){
    $replace = array("[NUMBER_CATEGORIES]" => $n_subcategories, "[CATEGORY_NAME]" => $current_category["name"]);
    echo strtr($TEMPLATE["SUBCATEGORIES"]["HEADING"],$replace);
    echo $TEMPLATE["SUBCATEGORIES"]["BEFORE_COLUMNS"];
    for ($x = 0; $x < ceil($n_subcategories/2); $x++){
    $replace = array("[CATEGORY_NAME]" => $subcategories[$x]["name"], "[CATEGORY_URL]" => $dir.'index.php?c='.$subcategories[$x]["id"]);
    echo strtr($TEMPLATE["SUBCATEGORIES"]["CATEGORY"],$replace);
    };
    echo $TEMPLATE["SUBCATEGORIES"]["BETWEEN_COLUMNS"];
    for ($x = ceil($n_subcategories/2); $x < $n_subcategories; $x++){
    $replace = array("[CATEGORY_NAME]" => $subcategories[$x]["name"], "[CATEGORY_URL]" => $dir.'index.php?c='.$subcategories[$x]["id"]);
    echo strtr($TEMPLATE["SUBCATEGORIES"]["CATEGORY"],$replace);
    };
    echo $TEMPLATE["SUBCATEGORIES"]["AFTER_COLUMNS"];
    echo $TEMPLATE["SUBCATEGORIES"]["FOOTER"];
    }else{
    $replace = array("[CATEGORY_NAME]" => $current_category["name"]);
    echo strtr($TEMPLATE["SUBCATEGORIES"]["NO_CATEGORIES"],$replace);
    };
    if ($current_category["pages"] == "y"){
    $replace = array("[CATEGORY_NAME]" => $current_category["name"], "[SUBMISSION_URL]" => $dir.'add_url.php?c='.$c);
    echo strtr($TEMPLATE["SUBMISSION_LINK"],$replace);
    flush();
    if ($s == 0) $s = 1;
    $n = 10;
    $sql = mysql_query("SELECT COUNT(*) AS total_pages FROM {$prefix}pages WHERE category = $c AND accepted = 'y'");
    $total_pages = mysql_result($sql,0,"total_pages");
    if ($total_pages > 0){
    $sql = mysql_query("SELECT id, url, title, description FROM {$prefix}pages WHERE category = $c AND accepted = 'y' ORDER BY title LIMIT ".($s-1).",$n");
    $n_pages = mysql_num_rows($sql);
    for ($x = 0; $x < $n_pages; $x++){
    $pages[$x] = mysql_fetch_array($sql, MYSQL_ASSOC);
    };
    };
    if ($show_additional_results){
    flush();
    require_once("include_ppc.php");
    $ppc_results = ppc_results($current_category["name"]);
    if ($s > $total_pages){
    $s2 = $s - $total_pages;
    }else{
    $s2 = 1;
    };
    $e2 = $s2 + min($s + $n - $total_pages - 1, count($ppc_results) - $s2 + 1);
    $total_pages += count($ppc_results);
    for ($x = $s2; $x < $e2; $x++){
    $n_pages += 1;
    $e += 1;
    $pages[$n_pages-1] = $ppc_results[$x];
    };
    };
    $e = min($s + $n - 1, $s + $n_pages - 1);
    if ($n_pages > 0){
    $replace = array("[STARTING_PAGE_NUMBER]" => $s, "[ENDING_PAGE_NUMBER]" => $e, "[TOTAL_PAGES]" => $total_pages, "[CATEGORY_NAME]" => $current_category["name"]);
    echo strtr($TEMPLATE["PAGES"]["HEADING"],$replace);
    for ($x = 0; $x < $n_pages; $x++){
    if ($pages[$x]["domain"]){
    $replace = array("[PAGE_NUMBER]" => $x, "[PAGE_TITLE]" => $pages[$x]["title"], "[PAGE_DESCRIPTION]" => $pages[$x]["description"], "[PAGE_URL]" => $pages[$x]["url"], "[PAGE_DOMAIN]" => $pages[$x]["domain"]);
    echo strtr($TEMPLATE["PAGES"]["FEED_PAGE"],$replace);
    }else{
    $replace = array("[PAGE_NUMBER]" => $x, "[PAGE_TITLE]" => $pages[$x]["title"], "[PAGE_DESCRIPTION]" => $pages[$x]["description"], "[PAGE_URL]" => $pages[$x]["url"], "[PAGE_DOMAIN]" => $pages[$x]["domain"]);
    echo strtr($TEMPLATE["PAGES"]["PAGE"],$replace);
    };
    };
    if ($s != 1 || $e != $total_pages){
    function pagination($s){
    global $c, $dir;
    if ($c != 1) { $query = "index.php?c=$c"; };
    if (($c != 1) & $s != 1){
    $query .= "&s=$s";
    }elseif ($s != 1){
    $query = "index.php?s=$s";
    };
    return $dir.$query;
    };
    echo $TEMPLATE["PAGES"]["PAGINATION"]["HEADING"];
    if ($s != 1){
    $previous = $s - $n;
    $replace = array("[PAGINATION_URL]" => pagination($previous));
    echo strtr($TEMPLATE["PAGES"]["PAGINATION"]["PREVIOUS"],$replace);
    };
    for ($x = 1; $x <= ceil($total_pages/$n); $x++){
    $current = ($x-1) * $n + 1;
    if ($current == $s){
    $replace = array("[PAGINATION_NUMBER]" => $x);
    echo strtr($TEMPLATE["PAGES"]["PAGINATION"]["CURRENT_NUMBER"],$replace);
    }else{
    $replace = array("[PAGINATION_NUMBER]" => $x, "[PAGINATION_URL]" => pagination($current));
    echo strtr($TEMPLATE["PAGES"]["PAGINATION"]["NUMBER"],$replace);
    };
    };
    if ($e < $total_pages){
    $next = $s + $n;
    $replace = array("[PAGINATION_URL]" => pagination($next));
    echo strtr($TEMPLATE["PAGES"]["PAGINATION"]["NEXT"],$replace);
    };
    echo $TEMPLATE["PAGES"]["PAGINATION"]["FOOTER"];
    };
    echo $TEMPLATE["PAGES"]["FOOTER"];
    }else{
    $replace = array("[CATEGORY_NAME]" => $current_category["name"]);
    echo strtr($TEMPLATE["PAGES"]["NO_PAGES"],$replace);
    };
    };
    echo $TEMPLATE["FOOTER"];
    ?>
     
    stephaneggy, Dec 17, 2004 IP
  2. stephaneggy

    stephaneggy Well-Known Member

    Messages:
    275
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #2
    I am a bit further I have this .htaccess:

    RewriteEngine on
    RewriteRule index.php$ index.php [PT]
    RewriteRule ^([0-9]+).php$ index.php?c=$1

    And If I type:
    http://www.onebigindex.com/dir/25.php
    I see the directory that haves that number, the only think I need now is the code to automaticly make the links the right way, who can help me out?
     
    stephaneggy, Dec 17, 2004 IP
  3. stephaneggy

    stephaneggy Well-Known Member

    Messages:
    275
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #3
    I am trying a lot things myself, I totally can't mod_rewrite and don't know anything about php but by looking to the samples and a bit of common sense I mentioned to archive this:

    http://www.onebigindex.com/dir/

    It works now with 25.php instead of index.php?c=25
    Now I am looking to tweak it and tweak the ad url and search pages.

    Does anybody know how to put you subcategories as a directory so:
    not: 26.php but:
    25/1.php

    or something like that?
     
    stephaneggy, Dec 17, 2004 IP
  4. Neilson

    Neilson Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    stephaneggy what do you have in your .htaccess to create eg /dir/2-11.php?
     
    Neilson, Mar 16, 2005 IP
  5. WhatiFind

    WhatiFind offline

    Messages:
    1,789
    Likes Received:
    257
    Best Answers:
    0
    Trophy Points:
    180
    #5
    I had similar problems, solved it like this:
    RewriteEngine on
    RewriteRule ^([0-9]+).php$ index.php?c=$1& [L]
    RewriteRule ^([0-9]+)add.php$ add_url.php?c=$1& [L]
    Code (markup):
    Then changed some code in files like index.php and add_url.php, this
    $category_url = $dir.'index.php?c='.$parent_categories[$x]["id"];
    Code (markup):
    to this:
    $category_url = $dir.$parent_categories[$x]["id"].'.php';
    Code (markup):
    It only works when the rewrite module is turned on from the apace server.

    The site from where my directory is hosted didn't support mod_rewrite, so I made this (thanx to exam from DP)
    <?
    $no = substr(basename($_SERVER['PHP_SELF']),0,-4); 
    require_once("http://www.yourdirectory.com/dir/index.php?c=$no"); 
    ?>
    Code (markup):
    and saved this code into dir/1.php, dir/2.php, dir/3.php and so on.
    Now when you open a file like 1.php, the php file includes index.php?c=1, works great, see dirSpace (still in beta)
     
    WhatiFind, Mar 16, 2005 IP
  6. Neilson

    Neilson Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I like how dirSpace is put together, l couldn't find a category that has enough entries to generate a second page. I have the same .htaccess which creates 1.php, 2.php etc well.. but reverts back to index.php?c=1&s=11 when faced with 1 2 Next and if I manually type 1-11.php in the address bar, it 404's
     
    Neilson, Mar 16, 2005 IP
  7. Neilson

    Neilson Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Ok Ive figured out the mod_rewrite, Im just struggling with href tag, where to point them to go to 10-11.php for page 2 or 10-22.php for page 3

    <A HREF="'.$dir.'index.php'.query($previous).'">'.$t07.'</A>
    <A HREF="'.$dir.'index.php'.query($current).'">'.$x.'</A>
    <A HREF="'.$dir.'index.php'.query($next).'">'.$t08.'</A>
     
    Neilson, Mar 17, 2005 IP
  8. WhatiFind

    WhatiFind offline

    Messages:
    1,789
    Likes Received:
    257
    Best Answers:
    0
    Trophy Points:
    180
    #8
    The directory is still in beta testing, an official release is coming soon, that's why you can't find any pages with more than 11 links, but i've written it like this: http://www.dirspace.com/dir/11/17.php and with more links it will be /22/17.php and so on.
    As said in previous post I can't use .htaccess (godaddy hosting) I've created static pages, like 1.php, 2.php and so on, and included php code in each file. for more links the code will be
    <?
    $no = substr(basename($_SERVER['PHP_SELF']),0,-4); 
    require_once("http://www.yourdirectory.com/dir/index.php?c=$no&s=11"); 
    ?>
    Code (markup):
     
    WhatiFind, Mar 17, 2005 IP
  9. samsam

    samsam Peon

    Messages:
    647
    Likes Received:
    53
    Best Answers:
    0
    Trophy Points:
    0
    #9
    samsam, Jul 21, 2005 IP