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 ofco.in
, how comewww.co.in
resolving different websitegoogle.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:
- compare the last part of url tlds in list , find matching one. [www.google.co.in -> in, www.co.in -> in]
- if no tld found, url invalid.
- if tld found , url has 3 parts or less, return tld result , exit.
- if tld found , url has more 3 parts, second search in list of slds. compare end of url against pattern ".sld.tld".
- if no entry found, return tld result , exit.
- if entry found, return sld.tld result , exit.
Comments
Post a Comment