Fix URL rewriting error on empty URLs

Fixes #54, fixes #59