If I ask a user for a URL, and they type in something like 'www.google.com', should I assume they meant http://www.google.com?

4 Answers 4


It depends on the context in which you're asking for a URL. If the url is supposed to be a fully qualified URL (http://example.com/foo/bar/baz) you can safely assume http:// if they haven't prefixed it with http, https, file, ftp, and any other possible acceptable protocols.

If, instead, you're asking for a url that may or may not be relative to the current domain, you wont be able to assume any protocol, although you could provide a default value of http:// as starter text

For a great example of where this is used, look no further than Stack Exchange's own link field in the popup used in the question/answer content editor (Ctrl + L).

  • Nice answer. I didn't know the ctrl + L thing. Commented May 6, 2012 at 6:17
  • +1, but I would not restrict the acceptable protocols to the few that are very well known. At work we use a custom URI protocol to exchange links to specific information within our software. Typing that in a browser or in the "Run" box on the start menu will start our software and execute a query that corresponds to the info in the URI. Custom URI protocols need to be registered, so you should be able to enumerate the known protocols... Commented May 6, 2012 at 8:25
  • @MarjanVenema, again, "It depends on the context in which you're asking for a URL". If you're asking a user for the link to their website (URL field in comments), you wouldn't accept anything other than http or https, so it truly depends on what protocols are accepted in the circumstances. If any protocol is acceptable, then you'd need to check if the user has provided a protocol.
    – zzzzBov
    Commented May 6, 2012 at 16:35
  • 1
    Yes, I wasn't arguing against that. I just tried to address that "if they haven't prefixed it with..." might just lead people to check for a specific and limited set of starter strings, instead of checking for all registered protocols, or, even better parsing the URI and checking for no or any protocol. Commented May 6, 2012 at 17:39

The majority of users on my websites never enter HTTP:// at the start of web address, and most web browsers now are not displaying it.

The default protocol should be http unless they specify something else (https for example).


Most web browsers with address correction make this assumption. So I'd think you could too.


I don't specify one way or the other from the user's pov, but when the link hits my server I prepend http:// if it's not present. It's a very simple line of PHP code:

if(!preg_match('/^http/', $url)) $url = "http://".$url;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.