more path rewriting, cherry-picking required features from goamz