Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How can I identify a base domain name from a given URL String

807580Jan 3 2010 — edited Jan 4 2010
I 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 1 2010
Added on Jan 3 2010
19 comments
2,116 views