What is the difference between URL and URI? This article will introduce to you what URL and URI are respectively? What is the use? Let everyone understand the difference between URL and URI, I hope it will be helpful to you.
What is the URL? What is the use?
A URL (Uniform Resource Locator) is the address of a resource on the Internet and can be defined as a string that refers to an address and is used to indicate the location of the resource and the protocol used to access it.
URL is the most commonly used way of locating a resource on the web, providing a way to retrieve a representation of a physical location by describing its network location or primary access mechanism.
The protocol is described in the URL that is used to retrieve the resource and resource name. If the resource is a web type resource, the URL contains http/https at the beginning. Likewise, if the resource is a file, it starts with ftp, if the resource is an email address, it starts with mailto.
URL contains the following information:
1. The protocol used to access the resource
2. The location of the server (either by IP address or domain name )
3. Port number on the server (optional)
4. The location of the resource in the server directory structure
5. Fragment identifier (optional)
Example:
As shown in the figure above, the first part is used for the protocol, and the rest of the part is used for resources consisting of domain names or program names.
What is URI? What is the use?
A URI (Uniform Resource Identifier) is a sequence of characters that identifies a logical or physical resource. Similar to a URL, it is also a string of characters. Identify resources on the Internet by using location, name, or both; it allows for uniform identification of resources.
There are two types of URIs, Uniform Resource Identifier (URL) and Uniform Resource Name (URN).
The general form of any URI is:
scheme:[// [user:password @] host [:port]] [/] path [?查询] [#片段]
Scheme (scheme ): The scheme lists the specific syntax and URI any relevant agreements. The scheme is case-insensitive and is followed by a colon. Ideally, the URI scheme should be registered with the Internet Assigned Numbers Authority (IANA), but non-registered schemes can also be used.
Permission component: The permission component consists of multiple parts: an optional authentication part, a host (consisting of a registered name or IP address), and an optional port number. The authentication part contains the username and password, separated by a colon, followed by the at (@) symbol. After @ is the hostname, then a colon, then a port number. It is important to note that IPv4 addresses must be in dotted decimal notation, and IPv6 addresses must be enclosed in parentheses.
Query (optional) : The query contains a string of non-hierarchical data. Although the syntax is not clearly defined, it is usually a sequence of attribute-value pairs separated by a delimiter, such as an ampersand or a semicolon. The query is separated from the previous part by a question mark.
Fragment (optional) : The fragment contains a fragment identifier that provides direction to the secondary resource.
The main difference between URL and URI
URL is a Uniform Resource Locator, used to identify resources; URI (Uniform Resource Identifier ) provides a simpler and extensible way of identifying resources. URL is a subset of URI. Let's take a look at the main difference between URL and URI.
1. Differences in functions
URL (Uniform Resource Locator) is mainly used to link to web pages, web components or programs on web pages, with the help of access methods (http, ftp, mailto and other protocols) to retrieve location resources.
URI (Uniform Resource Identifier) is used to define the identity of an item, where the word identifier means to distinguish one resource from other resources regardless of the method used (URL or URN).
2. It can be said that a URL is a URI (URL is a subset of URI), but a URI can never be a URL.
3. Protocol difference
URL specifies the protocol type to be used, while URI does not involve protocol specifications.
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
The above is the detailed content of What is the difference between URL and URI. For more information, please follow other related articles on the PHP Chinese website!