How can I identify a base domain name from a given URL String
807580Jan 3 2010 — edited Jan 4 2010I want to compare one URL String to another in order to determine whether or not one domain is local to the other. The problem starts when both domain names are sub-domains.
If I have:
a.example.com & b.example.com
Both are local to example.com, however, I can see no sensible way to programmatically determine this without first compiling a complete list of all domain extensions.
A fool's approach would be to tokenize the Strings with a "." delimiter and compare the second from last tokens, but this won't always work as there are domain extensions like .co.uk.
The only approach I can think of is to compile a full list of domain extensions and scan the Strings for, and remove, the extension. Then compare the right most token delimited by ".".
This would be a bit of a headache, can anyone think of a better way of doing this?
Cheers,
Finbarr