The concept of decoupling the actual files/folders from the URL is called routing. Many PHP frameworks include this kind of functionality, mostly using mod_rewrite. There is a nice blog post on PHP URL Routing that implements a simple standalone router class.
It creates mapping like this:
mysite.com/projects/show/1 --> Projects::show(1)
So the requested URL results in the function show()
of the class Projects
being called, with the parameter of 1
.
You can use this to build flexible mappings of pretty URLs to your PHP code.