TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: How do you check a url is valid?

3 pointsby lookingfjover 7 years ago
So it is trivial to check a url is valid using regex, but if you wanted to take this one step further and make sure it is a valid domain name that is registered and actually in use...how would you do this? I have a few ideas for how to achieve this with a Microservice but I feel like others may have solved this problem before and there may be better solutions out there.

4 comments

pwgover 7 years ago
First, you need to be precise in what you mean by &quot;valid&quot;.<p>&quot;Valid&quot; can encompass at least these four possibilities:<p>1) the url follows the correct syntax for url&#x27;s;<p>2) the url is valid as per #1 and further the &quot;host&quot; portion of the url (when it contains a name) can be resolved to an IP address;<p>3) the url is valid as per #2 and further there is a server located at the host (and optional port) value encoded in the URL that responds to requests;<p>4) The url is valid as per #3 and further the path and&#x2F;or query and fragment parts defines a valid path on the server running at the host:port encoded in the url.<p>#1 you can do yourself, as it is just a check that the syntax is correct.<p>All of numbers 2-4 require some form of &#x27;lookup&#x27; occur from some other system in order to verify &#x27;validity&#x27;.
lookingfjover 7 years ago
So I think in this instance I would deem valid to be: 1) the url is the correct format 2) the url resolves to an ip address 3) the url is registered and is in use. By this I mean it&#x27;s not one of the &quot;this domain name is for sale&quot; pages.<p>Number 3 is the novel and challenging piece of this.
icebrainingover 7 years ago
Check Whois, DNS and make an HTTP request?<p>This feels like an XY Problem, though. What are you trying to achieve by checking if the URL is valid?
评论 #15522282 未加载
ultrablueover 7 years ago
curllib will tell you whether there&#x27;s something there, presuming the network is available.<p>In fact, a simple HEAD request will suffice for that.<p>That would also prove that the domain is registered, presuming DNS is working.
评论 #15517576 未加载