How to create and use a fake directory structure?

I look at some sites that pretend that there is a directory structure in the URL and are wondering how.

I take charge of managing the website at work and review the code. They have a database for all pages, and they are created dynamically.

I can make the home page work on my local server, but I don’t know where to start with a fake directory structure. Example: http://www.bankcharges.com/bank-charges-advice/- there is no directory for this, but the content is in the database.

How did they do it?

The code I'm thinking of is related to:

index.php:

<?php

    include('includes/functions.php');

    $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";
?>

functions.php:

<?php

include('database.php');
include('settings.php');

//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;        
}

?>
+3
source share
3 answers

mod_rewrite - apache, . - .

.

+7

, , , ... URL- -

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /index.php?url=$0 [L,QSA]

, URL- http://www.bankcharges.com/bank-charges-advice/, http://www.bankcharges.com/index.php?url=bank-charges-advice/. index.php , (, - ). mod_rewrite.

+3

search google url.

here is the manual from apache

0
source

Source: https://habr.com/ru/post/1713253/


All Articles