Here's an example of the files involved:
.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
index.php
<?php
function getWebPath() {
$location = "";
// Read the relative URL into an array
if(isset($_SERVER['HTTP_X_REWRITE_URL'])) { // IIS Rewrite
$location = $_SERVER['HTTP_X_REWRITE_URL'];
} elseif(isset($_SERVER['REQUEST_URI'])) { // Apache
$location = $_SERVER['REQUEST_URI'];
} elseif(isset($_SERVER['REDIRECT_URL'])) { // Apache mod_rewrite (breaks on CGI)
$location = $_SERVER['REDIRECT_URL'];
} elseif(isset($_SERVER['ORIG_PATH_INFO'])) { // IIS + CGI
$location = $_SERVER['ORIG_PATH_INFO'];
}
return $location;
}
$location = getWebPath();
print_r($location);
The function above should become a method in your front controller class somewhere. You just need to subtract your base path from $location so you're left with the virtual path. Then you can do whatever you want -- e.g. simply split on '/' and then work your way through the path, passing each remainder to the next controller depending on the URI. You could also write more complicated routing rules using regular expressions (something Django and quite a few other frameworks do).
For example:
/profiles/hardik988
Would be passed to the controller in charge of 'profiles', which then decides what to do with the remainder of the path. It would likely look up the username and display the appropriate template.