Just in theory: Almost all modern websites work this way:
somedomain.com/layer1/layer2/action
For example:
http://stackoverflow.com/questions/ask
Typically this is done with .htaccess and ModRewrite Engine. A while ago I stumbled over an article that described something which came right out of php. I don't remember the name anymore. That piece of PHP code was aware of the currently opened URL. It was able to tell what domain is called, what TLD is called, what's the first directory, what's the second directory, what's the called file, etc.
I know the Kohana Framework uses this technology, but don't know where to look at. Anyone familiar with this?