You can use Altorouter in your project. Basically it does what you want but you need to read through the docs a bit.