URLencode the target URL properly

This avoids issues when the target URL includes query string parameters itself (i.e. `?foo=bar&baz=qux`).