最近在工作的時(shí)候發(fā)現(xiàn)蠢甲,對(duì)于域名解析服務(wù)的命名方式不是很了解呻澜。有的時(shí)候用了駝峰方式以及下劃線纠屋,但是并不可以正確解析涂臣。在網(wǎng)上搜索相關(guān)的文章真的少之又少,無(wú)奈之下只能自己翻看RFC標(biāo)準(zhǔn)文檔了售担。
DNS標(biāo)準(zhǔn)中關(guān)于域名語(yǔ)法的定義
描述DNS所對(duì)應(yīng)的RFC文檔是RFC 1034和RFC 1035赁遗,我們這里就只看1034就可以了(文檔居然是在1987年寫的,比我大半輪呢......90后的老鮮肉表示害怕)族铆。好在編寫文檔的大佬語(yǔ)言比較平易近人岩四,讀起來(lái)完全沒(méi)有啥晦澀的地方。
我們翻到文章的第3章-DOMAIN NAME SPACE and RESOURCE RECORDS骑素。
其中的第5節(jié)Preferred name syntax對(duì)于名稱的約定做出了解釋炫乓。下面截取一部分:
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
翻譯整理上面的話:
- 對(duì)于域名長(zhǎng)度的要求是小于等于63位
- 必須以字母開(kāi)頭刚夺,以字母或數(shù)字結(jié)尾
- 其中除了數(shù)字和字母之外,只能包含連字符“-”(言外之意使用下劃線不合法)
- 對(duì)于拼寫的大小寫不敏感末捣,也就是說(shuō)www.reibang.com等價(jià)于www.reibang.com
HTTP/1.1中關(guān)于地址的語(yǔ)法規(guī)范
上面是DNS關(guān)于域名的規(guī)范侠姑,由于現(xiàn)在服務(wù)之間主要還是通過(guò)http/1.1協(xié)議。所以落到實(shí)處的話箩做,還要以HTTP標(biāo)準(zhǔn)文檔中的描述為準(zhǔn)莽红。HTTP/1.1是RFC2616,其中有關(guān)URI比較的部分在第3章第2節(jié)的第3小節(jié)邦邦,下面貼出來(lái):
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>
上面我們可以看到那兩個(gè)大寫的MUST安吁,說(shuō)明host部分和scheme部分不區(qū)分大小寫。
結(jié)論
以下寫法
HTTP://www.reibang.com
Http://www.reibang.com
hTTP://www.reibang.com
HttP://www.reibang.com
hTTp://www.reibang.com
http://www.reibang.com
...
都是等價(jià)的燃辖。如果要在里面使用起連接作用的符號(hào)鬼店,只能使用“-”。