tld - More than one top level domain? -


in normal url, have protocol, subdomains (optional), domain name, top level domain , subdirectories.

for example: http://www.google.com/path. here www subdomain, google domain name , com tld; path subdirectory here. parsing simple programming task.

but problem comes when there more 1 tld's. example: www.google.co.in/path. here co.in tld. see there website name www.co.in present.

my doubts are:

  • how many top level domains can url have? in url how find top level domains, if there multiple tlds?
  • in above example google.co.in not subdomain of co.in, how come www.co.in resolving different website google.co.in?

if have write algorithm decides "www.co.in" belongs india top level domain (tld) , "www.google.co.in" belongs india second level domain (sld), go here , grab list:

https://wiki.mozilla.org/tld_list

then, process url this:

  1. compare the last part of url tlds in list , find matching one. [www.google.co.in -> in, www.co.in -> in]
  2. if no tld found, url invalid.
  3. if tld found , url has 3 parts or less, return tld result , exit.
  4. if tld found , url has more 3 parts, second search in list of slds. compare end of url against pattern ".sld.tld".
  5. if no entry found, return tld result , exit.
  6. if entry found, return sld.tld result , exit.

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -