URI and URL differences and differences between relative and absolute paths

Source: Internet
Author: User
Tags parent directory port number

One, url and URI definitions:

1.URL is written in the English language of the global resource Locator, and the address you enter in Internet Explorer is the URL. For example: NetEase http://www.163.com is a URL.
2.URI is every resource available on the Web-an HTML document, an image, a video fragment, a program, and is positioned by a generic resource identifier (Universal Resource Identifier, or "URI").
The format of the URL consists of the following three parts:
The first part is the agreement (or service mode);
The second part is the host IP address (and sometimes the port number) where the resource is stored;
The third part is the specific address of the host resource.
URIs are generally made up of three parts:
The naming mechanism for accessing resources.
Host name of the storage resource.
The name of the resource itself, represented by the path.

Two, url and URI differences:

(a) A URI is a relatively broad concept, and a URL is one of the URIs,

is a subset of the URI naming mechanism, which can be said to be abstract, and specifically to use URLs to locate resources.

(b) Every resource on the web, such as pictures, documents, videos, etc., is located by Uri, where the so-called positioning refers to the specific path on the server that the resources on the web are stored on the servers relative to the host server.

(c) A URL is a string used on the Internet to describe an information resource file, used on client programs and servers to locate a customer

Server, which not only locates this information resource, but also defines how to find the resource.

Popular Understanding:

URI is a resource positioning mechanism, it is relatively general positioning of resources, not limited to the client and server,

And the URL to locate all the resources on the Internet, as long as the resources on the Internet, there is a unique URL.


The difference between a relative path and an absolute path:

1. Absolute path

An absolute path is a path that a file really exists on the hard disk. For example "bg.jpg" This picture is stored in the hard disk "E:\book\ page layout code \ 2nd Chapter" directory, then "bg.jpg" the absolute path of this picture is "E:\book\ page cloth \ Code \ 2nd Chapter \bg.jpg". Then you should use the following statement if you want to specify a background picture of a Web page using an absolute path:

<body backround= "E:\book\ page layout \ Code \ 2nd Chapter \bg.jpg" >

2. Disadvantages of using absolute paths

In fact, in the Web page programming, rarely use absolute path, if use "E:\book\ page cloth \ Code \ 2nd Chapter \bg.jpg" To specify the location of the background picture, browsing on their own computer may be all right, but uploaded to the Web server browsing is likely not to display the picture. Since uploading to a Web server, it is possible that the entire Web site does not have an E drive on the Web server, possibly a D or H drive. Even if placed in the Web server e-disk, the Web server e-disk will not necessarily exist "E:\book\ page layout \ Code \ 2nd Chapter" This directory, so when browsing the Web page will not display the picture.

3. Relative path

In order to avoid this situation, it is often necessary to use relative paths when specifying files in a Web page. The so-called relative path is relative to its own target file location. For example, the "s1.htm" file refers to the "bg.jpg" image, because the "bg.jpg" image is in the same directory as the "s1.htm", then use the following code in the "s1.htm" file, as long as the relative position of the two files is unchanged ( That is, in the same directory), you can display the image correctly in the browser regardless of where you upload it to the Web server.

<body background= "Bg.jpg" >

One more example, assuming that the "s1.htm" file is in the same directory as "E:\book\ page layout \ code \ 2nd", and "bg.jpg" picture is located in the directory "E:\book\ page layout \ code \ 2nd \img", then "bg.jpg" picture relative to "s1.htm "The file is in the" IMG "subdirectory of the directory in which it is located, the statement referring to the picture should be:

<body background= "Img/bg.jpg" >

Note: The relative path uses the "/" character as the separator character for the directory, and the absolute path can use the "\" or "/" character as the delimiter character for the directory. Since the "IMG" Directory is a subdirectory under the "2nd Chapter" directory, there is no need to add the "/" character before "IMG".

Often used in relative paths ". /"to represent the previous level of the directory. If there are multiple top-level catalogs, you can use more than one ". /", for example" http://www.cnblogs.com/"represents the upper parent directory. Assuming that the "s1.htm" file is in the same directory as "E:\book\ page layout \ code \ 2nd" and the "bg.jpg" picture is in the same directory as "E:\book\ page layout \ Code", then the "bg.jpg" image is relative to the "s1.htm" file, is in the parent directory of the directory in which it is located, the statement referring to the picture should be:

<body background= ". /bg.jpg ">

One more example, assuming that the "s1.htm" file is located in the directory "E:\book\ page layout \ code \ 2nd", and "bg.jpg" picture is located in the directory of "E:\book\ page layout \ Code \img", then "bg.jpg" picture relative to "s1.htm" The file is in the "IMG" subdirectory in the parent directory of the directory in which it is located, the statement referring to the picture should be:

<body background= ". /img/bg.jpg ">


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.