It seems like it'd be a bit easier to strip the @url of any ending /'s and the path of any starting /'s and then join them with a single /.

if someone passes in a path that starts with '////foo' you're also not going to catch that and you'll only strip the leading /.