Hacker News new | past | comments | ask | show | jobs | submit login

Generally, the best way to handle this is using the public suffix list: https://publicsuffix.org/

org.hk is an entry in it, which means you should display the next section "up" from that, so that would be hkispa.org.hk as wanted here.




The public suffix doesn't list .ac.uk or .go.th (because it only lists somewhere the general public can register) so it's not especially useful for working out if something is a toppish-level domain.



You're right, apologies. I was Ctrl-F'ing with a leading dot.


The list doesn't only specify which domains users can register, but it is also used by browsers to determine what constitutes "same origin". This is related to security so even registrars which don't allow the general public to register these domains, it is very much in their interest to add an entry to the public suffix list.

For example, the maintainers of .ac.uk should very much care about the owner of "foo.ac.uk" not being able to set a cookie for "bar.ac.uk", which is partly what the PLS is used for!


What's a useful method to do that?


No idea for how you’d generate an exhaustive list, although one-off you could walk up a given URL’s host looking for A-records? You’d want some fail-safes there presumably. Perhaps you could do this with the common crawl db


Just in case you didn't catch the other message, the public suffix list does in fact include the domains mentioned.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: