How to extract from a URL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Stephen44905
    New Member
    • Sep 2010
    • 1

    How to extract from a URL

    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
    Last edited by Niheel; Sep 20 '10, 08:31 PM. Reason: elaborate, no signature links in posts
  • RonB
    Recognized Expert Contributor
    • Jun 2009
    • 589

    #2
    See:

    Comment

    Working...