If a domain does not have subdomains, use the domain name as the root prefix name
If it has subdomains, use the subdomains in reverse order as sub-prefix inside the root prefix by replacing . with /
Ignore port numbers in domain names
(Use Mozilla's Public Suffix List to solve the last requirement.)
--OR--
I've created an API to extract tld from a domain based on the PSL linked above.
Use the API so -
curl -H 'x-api-key: ' 'https://api.zeer0.com/v001/tools/public-suffix?domain=https://janata.in'
I'll send you the API key separately.
How is it useful?
The domain prefix is the last dot separated segment prior to the TLD. Therefore, for www.my-website.co.in, co.in is TLD, my-website is domain prefix, and www is the subdomain.
The root prefix will be my-website.co.in
The sub-prefix will be www.
How is this useful?
Once we move to this format, we can provide a cloud based shared inbox under a single domain to any user who does not already have web hosting. Say our cloud client is called shared-inbox.com. If a user wants to create a shared inbox on their personal domain - like my-domain.com - they can see their emails at com.my-domain.shared-inbox.com.