jeudi 15 février 2018

How do I determine the difference between the domain name and resource of a URL?

I am writing code that needs to respond to html redirections using the Location header. Mostly it works find, however, in some cases the header simply says to redirect to some resource, presumably on the same host, for example

Location: main.html

In other cases it will simply provide a new domain, for example

Location: abc.example.com

Now, how can I tell whether the redirection needs the existing host domain prefixed to the given partial URL without having to check all possible top-level domains in the suffix of the string? The only thing I can think to do is simply try one resultant URL and, if it fails, attempt the other one.

Has anyone got a clever solution or come across this problem before?




Aucun commentaire:

Enregistrer un commentaire