This function seems *very* specific for what the intended use case is, while it uses a name which implies it can handle all URIs, when in fact it only acts on a subset of URLs.