Change how URL is displayed

Discussion in 'PHP' started by RandomH3r0, May 25, 2007.

  1. #1
    On my site the URLs are displayed

    http://example.com/?id=catagory&page=page


    I would like to know how to make the URL display www.example.com/catagory/page.php

    With catagory and page depending on where the file name is located.

    How my site is setup now

    I have all the pages in /mods directoy

    So /mod/catagory/page.php displays as this.

    http://example.com/?id=catagory&page=page


    I use an index file that stays constant on all pages and just the middle column changes on each page.

    I am using this code on the index.php to get the pages
                  <?
    if (isset($_GET['page']) && isset($_GET['id']) &&
    file_exists('mods/'.$_GET[id].'/'.$_GET[page].'.php')) {
    include 'mods/'.$_GET[id].'/'.$_GET[page].'.php';
    }
    else { include "home.php";
    }
    ?>
    Code (markup):

    Thanks for your help
     
    RandomH3r0, May 25, 2007 IP
  2. tutankh

    tutankh Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,
    in .htaccess paste this code:
    
    RewriteEngine On
    RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+).php$ /?id=$1&page=$2
    x
    
    Code (markup):
    where x is just ENTER - blank new line.
    I think this should work fine for You.

    Regards,
    M
     
    tutankh, May 25, 2007 IP
  3. yedy72

    yedy72 Well-Known Member

    Messages:
    198
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #3
    copy all files to the webhome:confused:

    /mods -> / + .php

    so you can access all files thru /category/page

    or where is your problem?
     
    yedy72, May 25, 2007 IP
  4. RandomH3r0

    RandomH3r0 Peon

    Messages:
    265
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That worked tutankh . Thanks alottutankh
     
    RandomH3r0, May 25, 2007 IP