1

If I have a URL with no path component (e.g. in PHP can be served by index.php in the document root), which can take query parameters, is the / between the host name and query params strictly required? i.e. is this valid:

https://example.com?foo=bar

Or is the / to denote the end of the host name mandatory? i.e.

https://example.com/?foo=bar

Google Chrome seems to silently "fix" any URLs without the / after the host name, and the version without a / looks odd to me. But is the one without a / actually invalid? My Googling on this topic has lead me to a bunch of pages explaining he URL structure (including the relevant RFC), but nothing that clearly states what is required when there is no path. Answers that reference the specific section of an RFC especially appreciated.

Jim OHalloran
  • 5,859
  • 2
  • 37
  • 57
  • Given the automatic fix, the path is not "required". It's essential to the protocol and URL scheme however. – mario Nov 30 '20 at 07:16
  • @mario With regard to the automatic fix, it's absolutely not required in Google Chrome. But my assumption is that this "fix" is not specified in the RFCs and therefore different clients could fix in different ways. If the standards say that the URL is invalid without the extra / though, I have a problem that we might need to fix. – Jim OHalloran Nov 30 '20 at 07:21
  • @Luuk No it does not. That was one question I reviewed before posting this one. That question deals with the difference between a trailing slash on the path part (i.e. the semantic difference between file and folder), I want to know if a . is required when there is no path. – Jim OHalloran Nov 30 '20 at 07:23
  • 1
    Still unclear what this question is about. Chrome and other browsers automatically correct the missing path. And yes, the path is *technically* required. And no, it's the URL without path that looks wrong and would yield a request error. `echo "GET HTTP/1.0" | nc localhost 80` just doesn't fly. – mario Nov 30 '20 at 07:26
  • 1
    https://tools.ietf.org/html/rfc2616#section-3.2.2 – mario Nov 30 '20 at 07:28
  • @mario You've pointed me to exactly what I was looking for... Your netcat command line was a solid indication that no / didn't result in a valid GET request. But the BNF in the RFC you linked to confirms it. Thanks. – Jim OHalloran Nov 30 '20 at 07:51

0 Answers0