URI, URL, URN的概念和区分

本文解释了URI、URL和URN的概念及其区别。URI作为统一资源标识符,可以进一步细分为定位器(URL)和名称(URN)。URL不仅标识资源还提供定位方式,而URN则确保资源标识的唯一性和持久性。

URI, URL, URN的概念和区分

定义

A URI can be further classified as a locator, a name, or both. The term “Uniform Resource Locator” (URL) refers to the subset of URIs that, in addition to identifying a resource, provide a means of locating the resource by describing its primary access mechanism (e.g., its network “location”). The term “Uniform Resource Name” (URN) has been used historically to refer to both URIs under the “urn” scheme [RFC2141], which are required to remain globally unique and persistent even when the resource ceases to exist or becomes unavailable, and to any other URI with the properties of a name. [1]

So all URLs are URIs (actually not quite - see below), and all URNs are URIs - but URNs and URLs are different, so you can’t say that all URIs are URLs.

Examples[1]

URL & URI

Roger Pate
This is my name, which is an identifier. It is like a URI, but cannot be a URL, as it tells you nothing about my location or how to contact me. In this case it also happens to identify at least 5 other people in the USA alone.

4914 West Bay Street, Nassau, Bahamas
This is a locator, which is an identifier for that physical location. It is like both a URL and URI (since all URLs are URIs), and also identifies me indirectly as “resident of..”. In this case it uniquely identifies me, but that would change if I get a roommate.

I say “like” because these examples do not follow the required syntax.

URN

My name, Roger Pate, could be like a URN (Uniform Resource Name), except those are much more regulated and intended to be unique across both space and time.

Because I currently share this name with other people, it’s not globally unique and would not be appropriate as a URN. However, even if no other family used this name, I’m named after my paternal grandfather, so it still wouldn’t be unique across time. And even if that wasn’t the case, the possibility of naming my descendants after me make this unsuitable as a URN.

URNs are different from URLs in this rigid uniqueness constraint, even though they both share the syntax of URIs.

References

[1]http://stackoverflow.com/questions/176264/what-is-the-difference-between-a-uri-a-url-and-a-urn

<think>好的,我现在要解释URIURL之间的关系。首先,我需要确认自己对这些术语的理解是否正确。URI是统一资源标识符,而URL是统一资源定位符。根据之前学过的知识,URI是一个更广泛的概念,用来唯一标识一个资源,而URL则是URI的一种,不仅标识资源,还提供定位该资源的方法。不过,可能还有其他类型的URI,比如URN,这需要进一步理清。 首先,我应该回忆RFC标准中的定义。根据RFC 3986,URI可以分为URLURN或两者兼备。URL指定资源的位置访问方式,比如http、ftp等。URN则是通过名称来标识资源,不考虑其位置,例如ISBN号码。但实际中,URN的使用不如URL普遍,所以很多时候URIURL被混用,但严格来说URLURI的子集。 接下来,我需要确保区分URIURL的例子。例如,http://example.com/page.html是一个URL,同时也是URI,因为它标识并定位了资源。而urn:isbn:0451450523是一个URN,属于URI但不是URL,因为它没有指明资源的位置。 用户可能想知道它们的具体区别联系,所以需要用清晰的对比来说明。可能需要用比喻,比如URI像是身份证,唯一标识一个人,而URL像是住址,告诉你在哪里找到这个人。此外,还要提到URI可以同时是URLURN,但这种情况较少见。 同时,要检查是否有常见的误解。例如,有人认为URIURL是完全不同的,但实际上URLURI的一种。另外,需要确认语法结构,URI的通用格式包括scheme、authority、path、query、fragment等部分,而URL必须包含访问方法(如http)路径。 最后,总结时应该强调URI作为父类,包含URLURN,而URL是用于定位的子类。确保语言通俗易懂,结构清晰,分点或分步骤解释,避免技术术语过于复杂。</think>URI(统一资源标识符)URL(统一资源定位符)是互联网中标识定位资源的核心概念,二者的关系可通过以下步骤理解: --- ### 1. **定义区分** - **URI(Uniform Resource Identifier)** 广义概念,用于**唯一标识**一个资源。例如:一本书的ISBN号、一个人的身份证号,仅标明身份但不涉及位置或访问方式。 - **URL(Uniform Resource Locator)** URI的子集,不仅标识资源,还指明**如何定位访问**该资源。例如:网页地址、文件路径。 --- ### 2. **包含关系** - **URI包含URLURN** URI分为两类: - **URL**:通过位置标识资源(如`https://example.com/image.jpg`)。 - **URN**:通过名称标识资源(如`urn:isbn:9780141036144`,标识《1984》的ISBN)。 > 📌 实际应用中,URN较少见,大多数URIURL。 --- ### 3. **类比解释** - **URI ≈ 身份证号** 唯一标识身份,但不透露住址或联系方式。 - **URL ≈ 家庭住址** 既标识身份(某个人),又说明如何找到他(具体地址)。 --- ### 4. **语法结构对比** - **URI通用格式** ```plaintext scheme:[//authority][/path][?query][#fragment] ``` - 例:`mailto:user@example.com`(标识邮箱,未指定位置,属于URI但不是URL)。 - **URL必须包含** - **协议(Scheme)**:如`http`、`ftp`。 - **路径(Path)**:如`/page.html`。 > 例:`https://www.google.com/search?q=URI+vs+URL` 是URL(也是URI)。 --- ### 5. **总结关系** - **URI是抽象父类,URL是具体子类** - 所有URL都是URI,但并非所有URI都是URL。 - URI侧重“标识”,URL侧重“定位+访问方式”。 --- ### 6. **常见误区澄清** - ❌ **“URIURL完全无关”** → ✅ URLURI的一种。 - ❌ **“URI必须包含协议”** → ✅ URI可以是纯名称(如URN),无需协议。 通过以上分析,可明确:URI是更广泛的概念URL是其实现定位功能的具体形式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值