URI、URL 和 URN 之间有什么区别?
URI、URL 和 URN 之间有什么区别?我读过很多网站(甚至维基百科)但我不明白。
URI:http://www.foo.com/bar.html
网址:http://www.foo.com/bar.html
URN:bar.html
这是正确的吗?
What's the difference between an URI, URL and URN? I have read a lot of sites (even Wikipedia) but I don't understand it.
URI: http://www.foo.com/bar.html
URL: http://www.foo.com/bar.html
URN: bar.html
Is this correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
统一资源标识符 (
URI
) 是用于标识 Internet 上的名称或资源的字符串。URI 通过位置和/或名称来标识资源。 URI 有两种专门化,即 URL 和 URN。
统一资源定位符 (
URL
) 是统一资源标识符 (URI) 的子集,用于指定所识别资源的位置可用以及检索它的机制。 URL 定义了如何获取资源。它不一定是 HTTP URL (http://
),URL 也可以以ftp://
或smb://,指定用于获取资源的协议。
统一资源名称 (
URN
) 是使用 URN 方案的统一资源标识符 (URI),并不暗示所标识资源的可用性。 URN(名称)和 URL(定位符)都是 URI,并且特定的 URI 可能同时既是名称又是定位符。此图(来源)可视化URI、URN 和 URL 之间的关系:
URN 是一部分一个更大的互联网信息架构,由 URN、URC 和 URL 组成。
bar.html 不是 URN。 URN 类似于人名,而 URL 类似于街道地址。 URN 定义某物的身份,而 URL 提供位置。本质上,URN 与 URL 的区别是“什么”与“何处”。 URN 必须采用这种形式
::= "瓮:"; ":"
其中
是命名空间标识符,
是命名空间特定字符串。换句话来说:
URL可以说,唯一能使其 100% 清晰的就是提供一个不是 URL 的 URI 示例。我们可以使用 RFC3986 中的示例:
A Uniform Resource Identifier (
URI
) is a string of characters used to identify a name or a resource on the Internet.A URI identifies a resource either by location, or a name, or both. A URI has two specializations known as URL and URN.
A Uniform Resource Locator (
URL
) is a subset of the Uniform Resource Identifier (URI) that specifies where an identified resource is available and the mechanism for retrieving it. A URL defines how the resource can be obtained. It does not have to be a HTTP URL (http://
), a URL can also start withftp://
orsmb://
, specifying the protocol that's used to get the resource.A Uniform Resource Name (
URN
) is a Uniform Resource Identifier (URI) that uses the URN scheme, and does not imply availability of the identified resource. Both URNs (names) and URLs (locators) are URIs, and a particular URI may be both a name and a locator at the same time.This diagram (source) visualizes the relationship between URI, URN, and URL:
The URNs are part of a larger Internet information architecture which is composed of URNs, URCs and URLs.
bar.html is not a URN. A URN is similar to a person's name, while a URL is like a street address. The URN defines something's identity, while the URL provides a location. Essentially URN vs. URL is "what" vs. "where". A URN has to be of this form
<URN> ::= "urn:" <NID> ":" <NSS>
where<NID>
is the Namespace Identifier, and<NSS>
is the Namespace Specific String.To put it differently:
I'd say the only thing left to make it 100% clear would be to have an example of an URI that is not an URL. We can use the examples in RFC3986:
下面我总结了Prateek Joshi 的精彩解释。
理论:
即:
举个例子:
另外,如果您还没有阅读过,我建议您阅读 罗杰·佩特的回答。
Below I sum up Prateek Joshi's awesome explanation.
The theory:
That is:
And for an example:
Also, if you haven't already, I suggest reading Roger Pate's answer.
URL -- 统一资源定位符
包含有关如何从资源位置获取资源的信息。例如:
http://example.com/mypage.html
ftp://example.com/download.zip
mailto:[电子邮件受保护]
file:///home/user/file. txt
http://example.com/resource?foo=bar#fragment
/other/link.html
(相对 URL,仅在上下文中有用URL始终以协议 (
http
) 开头,通常包含网络主机名 (example.com
) 等信息,并且通常包含文档路径 (>/foo/mypage.html
)。 URL 可以具有查询参数和片段标识符。URN -- 统一资源名称
按名称标识资源。它始终以前缀
urn:
开头,例如:urn:isbn:0451450523
通过 ISBN 编号识别书籍。urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66
全局唯一标识符urn:publishing:book
- 将文档标识为书籍类型的 XML 命名空间。URN 可以识别想法和概念。它们不仅限于识别文件。当 URN 确实代表文档时,它可以由“解析器”转换为 URL。然后可以从 URL 下载该文档。
URI -- 统一资源标识符
URI 包含 URL、URN 和其他指示资源的方式。
既不是 URL 也不是 URN 的 URI 示例是 数据 URI,例如 <代码>数据:,Hello%20World。它不是 URL 或 URN,因为 URI 包含数据。它既不命名它,也不告诉您如何通过网络找到它。
还有统一资源引用 (URC),它指向有关文档的元数据而不是文档本身。 URC 的一个示例是用于查看网页源代码的指示符:
view-source:http://example.com/
。 URC 是另一种类型的 URI,它既不是 URL 也不是 URN。常见问题
我听说我不应该再说 URL,为什么?
HTML 的 w3 规范表示
href
可以包含 URI,而不仅仅是 URL。您应该能够输入 URN,例如
。然后,您的浏览器会将该 URN 解析为 URL 并为您下载该书。
有浏览器真正知道如何通过 URN 获取文档吗?
据我所知,现代 Web 浏览器确实实现了数据 URI 方案。
URI 可以同时是 URL 和 URN 吗?
好问题。我在网上看到很多地方都说这是真的。我还没有找到任何既是 URL 又是 URN 的示例。我不明白这是怎么可能的,因为 URN 以
urn:
开头,这不是有效的网络协议。URL 和 URI 之间的区别与相对还是绝对有关吗?
不是。相对 URL 和绝对 URL 都是 URL(和 URI)。URL
和 URI 之间的区别是否与它是否具有查询参数有关?
不。带和不带查询参数的 URL 都是 URL(和 URI)。URL
和 URI 之间的区别是否与它是否具有片段标识符有关?
不。带有和不带有片段标识符的 URL 都是 URL(和 URI)。
tel:
URI 是 URL 还是 URN?例如
电话:1-800-555-5555
。它不以urn:
开头,并且具有用于通过网络访问资源的协议。它必须是一个 URL。但是 w3C 现在不是说 URL 和 URI 是同一件事吗?
是的。 W3C 意识到这方面存在很多混乱。他们发布了一份 URI 澄清文档,表示现在可以使用 URL 和 URI可以互换。将 URI 严格分为 URL、URN 和 URC 等不同类型不再有用。
URL -- Uniform Resource Locator
Contains information about how to fetch a resource from its location. For example:
http://example.com/mypage.html
ftp://example.com/download.zip
mailto:[email protected]
file:///home/user/file.txt
http://example.com/resource?foo=bar#fragment
/other/link.html
(A relative URL, only useful in the context of another URL)URLs always start with a protocol (
http
) and usually contain information such as the network host name (example.com
) and often a document path (/foo/mypage.html
). URLs may have query parameters and fragment identifiers.URN -- Uniform Resource Name
Identifies a resource by name. It always starts with the prefix
urn:
For example:urn:isbn:0451450523
to identify a book by its ISBN number.urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66
a globally unique identifierurn:publishing:book
- An XML namespace that identifies the document as a type of book.URNs can identify ideas and concepts. They are not restricted to identifying documents. When a URN does represent a document, it can be translated into a URL by a "resolver". The document can then be downloaded from the URL.
URI -- Uniform Resource Identifier
URIs encompasses both URLs, URNs, and other ways to indicate a resource.
An example of a URI that is neither a URL nor a URN would be a data URI such as
data:,Hello%20World
. It is not a URL or URN because the URI contains the data. It neither names it, nor tells you how to locate it over the network.There are also uniform resource citations (URCs) that point to meta data about a document rather than to the document itself. An example of a URC would be an indicator for viewing the source code of a web page:
view-source:http://example.com/
. A URC is another type of URI that is neither URL nor URN.Frequently Asked Questions
I've heard that I shouldn't say URL anymore, why?
The w3 spec for HTML says that the
href
of an anchor tag can contain a URI, not just a URL. You should be able to put in a URN such as<a href="urn:isbn:0451450523">
. Your browser would then resolve that URN to a URL and download the book for you.Do any browsers actually know how to fetch documents by URN?
Not that I know of, but modern web browser do implement the data URI scheme.
Can a URI be both a URL and a URN?
Good question. I've seen lots of places on the web that state this is true. I haven't been able to find any examples of something that is both a URL and a URN. I don't see how it is possible because a URN starts with
urn:
which is not a valid network protocol.Does the difference between URL and URI have anything to do with whether it is relative or absolute?
No. Both relative and absolute URLs are URLs (and URIs.)
Does the difference between URL and URI have anything to do with whether it has query parameters?
No. Both URLs with and without query parameters are URLs (and URIs.)
Does the difference between URL and URI have anything to do with whether it has a fragment identifier?
No. Both URLs with and without fragment identifiers are URLs (and URIs.)
Is a
tel:
URI a URL or a URN?For example
tel:1-800-555-5555
. It doesn't start withurn:
and it has a protocol for reaching a resource over a network. It must be a URL.But doesn't the w3C now say that URLs and URIs are the same thing?
Yes. The W3C realized that there is a ton of confusion about this. They issued a URI clarification document that says that it is now OK to use URL and URI interchangeably. It is no longer useful to strictly segment URIs into different types such as URL, URN, and URC.
URI(统一资源标识符)根据维基百科:
URL(统一资源定位符)是暗示与资源交互机制的URI。例如 https://www.google.com 指定使用 HTTP 作为交互机制。并非所有 URI 都需要传达特定于交互的信息。
URN(统一资源名称) 是 URI 的一种特定形式,其方案为 urn。有关 URI 的一般形式的更多信息,请参阅 https://en.wikipedia.org/ wiki/Uniform_Resource_Identifier#Syntax
IRI(国际资源标识符) 是对URI 的定义允许我们在 URI 中使用国际字符。
URI (Uniform Resource Identifier) according to Wikipedia:
URL (Uniform Resource Locator) is a URI that implies an interaction mechanism with resource. for example https://www.google.com specifies the use of HTTP as the interaction mechanism. Not all URIs need to convey interaction-specific information.
URN (Uniform Resource Name) is a specific form of URI that has urn as it's scheme. For more information about the general form of a URI refer to https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Syntax
IRI (International Resource Identifier) is a revision to the definition of URI that allows us to use international characters in URIs.