Add 'rewrite' middleware

Closes #47 
Otherwise looks good