How can I create and use a false directory structure?


I have been looking at some sites that pretend that there is a directory structure in the URL and wondered 'how?'.

I am taking control of a website at work and have looked over the code. They have a database for all the pages and they are created dynamically.

I can get the homepage working on my local server but I don't have a clue as to where to start with the fake directory structure. An example is - there is no directory for this but the content is in the database.

How have they done this?

The code this I think is related to is:




    $activeTab = "navhome";
    $sent = false;

    $title = (isset($_GET['title']))? mysql_real_escape_string($_GET['title']) : 'Home';
    $title = str_replace('-',' ', $title);

    if($title != '') {  

        $sql = "SELECT *
                FROM contents
                WHERE name LIKE '%$title%'
                LIMIT 1";

        $result = @mysql_query($sql);
        $row = mysql_fetch_assoc($result);

    //Set page title
    $pagetitle = (isset($row['name']) && $title != 'Home')? ucwords($row['name']) : "Bank Charges";




//Nice URL's
function url($str){
$arr = array('!','"','£','$','%','^','&','*','(',')','_','+','{','}',':','@','~','<','>','?','|',',','.','\\','/',';',']','[','\'');
$str = str_replace($arr,"", str_replace(" ","-",strtolower($str)));
return $str;

function isEven($v){
    if($v % 2 == 0) return true;


mod_rewrite is the apache module that allows this to occur. Other web servers have their own implementations.

For a beginners guide, check out this blog post.