added rewrite to location/proxy & vhost

Rebase #222 and add tests for the new functionality, and simplify some of the logic used.

Resolves #138 (original request adding rewrite support)
Resolves #222 (updated request adding rewrite support, missing tests)
Resolves #234 (raised after adding validations - this should add back the missing functionality)