There are several ways of doing it.
You can use mod-rewrite to rewire foo to foo.php so that requests for /bar gets handled by /bar.php.
You can use directories, and default-files, so that you link to the direcory /foo/ which gets handled by /foo/index.php
You can set a php-script as the handler for 404-errors, then you just link to nonexistant files, and the handler-file deals with it however it likes. (typically by using some sort of map from url to php-file)
You can tell your webserver that all request for a certain webserver, is to be handled by php.
The first or second solution is the simplest, but the 2 last ones gives the best flexibility, and variants thereof is what most of the bigger frameworks do.