Which is the best way to create a rooting or indexing system.

i.e forum/posts/22
by going to this url how to display the 22 id post

and by going to forum/posts/22/edit
go to editing the 22nd post.

the method i have come across is as follows

.htaccess in the root directory

RewriteEngine On
RewriteRule !(\.gif|\.png|\.jpe?g|\.css|\.js|\.php|^public/.*)$ index.php [nocase,last]

index.hp also in the root directory using the following method

PHP Code:
// Requested URL
// Removes Apllication root from url
$url str_replace('/tumblelog/'''$url);
$routes = array(
'url' => '/^posts\/(?P<id>\d+)$/''controller' => 'posts''view' => 'show'),
'url' => '/^posts\/(?P<id>\d+)\/edit$/''controller' => 'posts''view' => 'edit')
$params = array();
$route_match false;
$routes as $urls => $route)
preg_match($route['url'], $url$matches))
$params array_merge($params$matches);
$route_match true;
$route_match) { exit('no route found'); }
//print('controller: '.$route['controller'].' view:'.$route['view'].' id:'.$params['id']);
    //echo $url;

CAN some one tell me if this is the correct method else direct me to the right resouces