The mod rewrite is a little confusing, but you can easily find premade examples, and then edit to your needs.
The php scripting is not very exciting. All you do is get the URL, and then chop off the domain and tld, and then explode it based on "/". It get's messy if you want to try and respect query strings as well.