Determine if domain is zone apex or subdomain

Dan asked:

I’m trying to write a script where part of its functionality depends on if a user-provided domain is a zone apex ( or not ( What is a robust way to determine if I’m dealing with a zone apex or a subdomain? I’m hoping for a purely pattern-based approach but that seems tricky (example: is not a root domain but is).

Are there any tried and true approaches to determine if a zone is a root domain or not?

I answered:

The Public Suffix List indicates lists of top level and second level domains under which one can register a domain name. If a name has exactly one more level beyond its matching entry on this list, then it’s the zone apex.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.