域名命名规范的探究

最近在工作的时候发现,对于域名解析服务的命名方式不是很了解。有的时候用了驼峰方式以及下划线,但是并不可以正确解析。在网上搜索相关的文章真的少之又少,无奈之下只能自己翻看RFC标准文档了。

DNS标准中关于域名语法的定义

描述DNS所对应的RFC文档是RFC 1034RFC 1035,我们这里就只看1034就可以了(文档居然是在1987年写的,比我大半轮呢......90后的老鲜肉表示害怕)。好在编写文档的大佬语言比较平易近人,读起来完全没有啥晦涩的地方。

我们翻到文章的第3章-DOMAIN NAME SPACE and RESOURCE RECORDS。
其中的第5节Preferred name syntax对于名称的约定做出了解释。下面截取一部分:

Note that while upper and lower case letters are allowed in domain
names, no significance is attached to the case.  That is, two names with
the same spelling but different case are to be treated as if identical.

The labels must follow the rules for ARPANET host names.  They must
start with a letter, end with a letter or digit, and have as interior
characters only letters, digits, and hyphen.  There are also some
restrictions on the length.  Labels must be 63 characters or less.

For example, the following strings identify hosts in the Internet:

A.ISI.EDU  XX.LCS.MIT.EDU  SRI-NIC.ARPA

翻译整理上面的话:

  1. 对于域名长度的要求是小于等于63位
  2. 必须以字母开头,以字母或数字结尾
  3. 其中除了数字和字母之外,只能包含连字符“-”(言外之意使用下划线不合法)
  4. 对于拼写的大小写不敏感,也就是说www.jianshu.com等价于www.JIANSHU.com

HTTP/1.1中关于地址的语法规范

上面是DNS关于域名的规范,由于现在服务之间主要还是通过http/1.1协议。所以落到实处的话,还要以HTTP标准文档中的描述为准。HTTP/1.1是RFC2616,其中有关URI比较的部分在第3章第2节的第3小节,下面贴出来:

When comparing two URIs to decide if they match or not, a client
   SHOULD use a case-sensitive octet-by-octet comparison of the entire
   URIs, with these exceptions:

      - A port that is empty or not given is equivalent to the default
        port for that URI-reference;

        - Comparisons of host names MUST be case-insensitive;

        - Comparisons of scheme names MUST be case-insensitive;

        - An empty abs_path is equivalent to an abs_path of "/".

   Characters other than those in the "reserved" and "unsafe" sets (see
   [RFC 2396](https://tools.ietf.org/html/rfc2396) [[42](https://tools.ietf.org/html/rfc2616#ref-42 ""Uniform Resource Identifiers (URI): Generic Syntax and Semantics"")]) are equivalent to their ""%" HEX HEX" encoding.

   For example, the following three URIs are equivalent:

      [http://abc.com:80/~smith/home.html](http://abc.com/~smith/home.html)
      [http://ABC.com/%7Esmith/home.html](http://abc.com/~smith/home.html)
      [http://ABC.com:/%7esmith/home.html](http://abc.com/~smith/home.html)</pre>

上面我们可以看到那两个大写的MUST,说明host部分和scheme部分不区分大小写。

结论

以下写法

HTTP://WWW.JIANSHU.COM
Http://WWW.jianshu.COM
hTTP://www.JIANSHU.COM
HttP://www.jianshu.COM
hTTp://WwW.jIaNsHu.CoM
http://www.jianshu.com
...

都是等价的。如果要在里面使用起连接作用的符号,只能使用“-”

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容