I've seen this question posted previously on bytes.com, but the question was never fully answered.
Hypothetically, use this as a URL: http://subdomain1.subdomain2.domain.subdomain3.com What I'm looking for is a way to extract just the domain name leaving the subdomains and any other data excluded.
At any given point, I won't know how many subdomains are included in the URL. So using a regex probably isn't the best idea as the domain could exist here: domain.com, or here domain.com.co.u k or here: k12.oh.us.
It seems like what I'm seeking could be done through DNS, yet, with many websites that are hosted sharing an IP address, I don't know that DNS is the best means either.
I've thought about status code. A subdomain is redirected to somewhere else within the domain, yet using the module LWP, returns a 200 and not a 301.
So is there a way I can either extract just the domain name, excluding subs, etc., from the URL or, when connecting to a server where a subdomain exists in the URL, to get a code back from the server indicating this?
Any help whether it's possible or not would be appreciated.
Stephen
Hypothetically, use this as a URL: http://subdomain1.subdomain2.domain.subdomain3.com What I'm looking for is a way to extract just the domain name leaving the subdomains and any other data excluded.
At any given point, I won't know how many subdomains are included in the URL. So using a regex probably isn't the best idea as the domain could exist here: domain.com, or here domain.com.co.u k or here: k12.oh.us.
It seems like what I'm seeking could be done through DNS, yet, with many websites that are hosted sharing an IP address, I don't know that DNS is the best means either.
I've thought about status code. A subdomain is redirected to somewhere else within the domain, yet using the module LWP, returns a 200 and not a 301.
So is there a way I can either extract just the domain name, excluding subs, etc., from the URL or, when connecting to a server where a subdomain exists in the URL, to get a code back from the server indicating this?
Any help whether it's possible or not would be appreciated.
Stephen
Comment