📜  URL vs URI (1)

📅  最后修改于: 2023-12-03 15:05:46.324000             🧑  作者: Mango

URL vs URI

Introduction

Uniform Resource Identifier (URI) and Uniform Resource Locator (URL) are often used interchangeably, but they are not exactly the same thing. They are both used to identify and locate resources on the internet, but they have some important differences.

URI

A URI is a string of characters that identifies an abstract or physical resource. It is a standardized format for identifying resources with a name, a protocol (such as http, ftp, etc.), and other optional components such as an authority (such as user@host), a port number, and a path. A URI can be used to identify any resource, not just web pages.

Syntax

The syntax for a URI is as follows:

scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
  • scheme - The protocol used to access the resource (e.g. http, ftp, mailto, file, etc.).
  • user - The username to use for authentication (if required).
  • password - The password to use for authentication (if required).
  • host - The hostname or IP address of the server hosting the resource.
  • port - The optional port number to use when accessing the resource.
  • path - The path of the resource on the server.
  • query - Any optional parameters to be passed to the resource.
  • fragment - An optional anchor link within the resource.
Example
mailto:john@example.com
tel:+15555555555
urn:isbn:0451450523
URL

A URL is a type of URI that specifies the location of a resource and the protocol used to access it. It can be used to locate web pages, images, videos, and other resources on the internet.

Syntax

The syntax for a URL is the same as that of a URI, but with some additional components:

scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
  • scheme - The protocol used to access the resource (e.g. http, ftp, mailto, file, etc.).
  • user - The username to use for authentication (if required).
  • password - The password to use for authentication (if required).
  • host - The hostname or IP address of the server hosting the resource.
  • port - The optional port number to use when accessing the resource.
  • path - The path of the resource on the server.
  • query - Any optional parameters to be passed to the resource.
  • fragment - An optional anchor link within the resource.
Example
http://www.example.com/index.html
ftp://ftp.example.com/documents/document.pdf
Conclusion

In summary, URI is a more general term that includes URLs. URLs are a specific type of URI that identifies the location of a resource on the internet. When you need to identify a resource on the web, you should use a URL, but if you need to identify a resource that is not on the web, you can use a URI.