This question has been asked in various permutations, but I haven\'t found the right combination that answers my particular question.
You should have a look at rack-rewrite - it's essentially Apache re-write but in Ruby form, and usable on Heroku.
This will allow you to create all sorts of Rack level rules and what redirections etc should occur and when.