问题
I have done some reading on proper Hostname syntax and can't figure out what is a really proper Hostname/URL syntax Can you please tell me if the following URLs are syntactically correct?
1.2.3.4.5.6.7/something
10.123.143.13333/something
1.2.3.4.5.6.7.com/something
some.host.name.com.org/something
Those are just some examples that i couldn't figure out. Are those URLs correct?
回答1:
These are not URLs, as they are missing a scheme.
Assuming that you mean HTTP URLs, they would be:
http://1.2.3.4.5.6.7/something
http://10.123.143.13333/something
http://1.2.3.4.5.6.7.com/something
http://some.host.name.com.org/something
RFC 3986 defines the syntax of the host subcomponent for all URIs (and RFC 2616 for HTTP(S) URIs follows that).
The host names of your example URIs would be:
1.2.3.4.5.6.7
10.123.143.13333
1.2.3.4.5.6.7.com
some.host.name.com.org
Valid host names follow the syntax defined (in the section linked above) by IP-literal, IPv4address, or reg-name:
Check if
IP-literal:As an
IP-literalrequires enclosing square brackets ([…]), none areIP-literalhost names.Check if
IPv4address:As an
IPv4addressmust contain exactly three.characters,1.2.3.4.5.6.7,1.2.3.4.5.6.7.com, andsome.host.name.com.orgcan’t beIPv4addresshost names.While
10.123.143.13333has three., "13333" is not a validdec-octet, so it’s not anIPv4address.Check if
reg-name:All of your examples are valid
reg-namehost names, as0-9,a-z, and.are allowed characters.Note that this does not mean that these are valid domain names in the DNS. RFC 3986 "does not mandate a particular registered name lookup technology".
来源:https://stackoverflow.com/questions/29467752/host-names-and-url-syntax