Rename history support middleware
Improve checks for rewriting in middleware