I had the pleasure to take a peak at WordPress source code; i was wondering how they managed the custom url feature, but i couldn’t really get it.
The rewrite rules inside wordpress .htaccess file simply redirect all requests to index.php.
After that, it’s a mystery to me: how do they make example.com/this/title/is/cool/
match index.php?p=233 ?
Once it’s redirected to index.php, that file can look at
$_SERVER['REQUEST_URI']
to determine what is in thethis/title/is/cool
portion, and then go look up what page to serve from a database, since the REQUEST_URI lists the full URI string, even though the actual page url that was redirected to is only the first portion of it.For instance,
gets rewritten to
This will actually result in http://www.example.com/index.php being loaded, but
$_SERVER['REQUEST_URI']
will have the full/index.php/foo/bar/
within it.Some apps use a different approach, they use
.htaccess
to just take the trailing “directories” and put them into the query string, so that the rewrite becomes something like this:in which case the supplied path is available in
_GET['path']
.