Move proxy URL rewriting into a function

...so it can be used more generically

Change-Id: I48288d264111f502887d00d775bd40f7e7a9e189