Add helper function proxify_url()

This helps to reduce the amount of reused code, and makes the code easier to manage.
Fix url encoding

Apparently files and directories can have spaces in them. Who knew?