Relative Path and absolute path,

Source: Internet
Author: User
1. relative and absolute paths
There are three types of document paths: absolute path, root relative path, and document relative path.

The absolute path is the full path that includes the Server Protocol (in this example, HTTP). For example, the full path of "Hong Neng online-computer Park" is http://www.hongen.com/pc/index.htm. if you want to link a document outside the site, use absolute paths.

The relative path includes the root relative path (site root) and document relative path (document.
As mentioned above, when editing a webpage on a local disk, You need to select a folder to define the local site and simulate the root folder on the server, the system determines the local file location of all links based on this folder, and the root in the relative path refers to this folder.

The path to the relative path (also known as the relative directory) starts with "/". The path is calculated from the root directory of the current site. For example, the myweb directory of the d disk we created earlier is the site named "myweb". Then, the path "/index.htm" indicates that the file location is D: \ myweb \ index.htm. The root relative path applies to files in the environment frequently when the link content is changed, so that the link can still take effect even if the files in the site are moved.

If the directory structure is too deep, it is better to use the relative path when referencing the files under the root directory. For example, if a webpage file references a graph in the IMG directory under the root directory, the relative path of the document is displayed as: ".. /.. /.. /.. /.. /img/a.gif, and the relative path is expressed as "/img/a.gif.

Note: When previewing a file, content linked with the root relative path is not displayed in the local browser, because the browser does not recognize the root folder of the site as a server.

In this case, we can virtualize the root directory of the site into a disk. For example, if you want to browse files under D: \ myweb, you can select "run" in the Windows "start" menu to bring up the "run" dialog box.

Enter "subst I: D: \ myweb". The myweb folder on disk D is virtualized as an I disk, and you can view the webpage under disk I in a browser, the content linked with the root relative path can be displayed normally.

The relative path of a document refers to the folder containing the current document, which is calculated based on the folder where the current webpage is located. For example, if the current webpage is located at D: \ myweb \ mypic, then:

A.htm indicates D: \ myweb \ mypic \ a.htm;

"../A.htm" is equivalent to D: \ myweb \ a.htm, where "../" indicates the level-1 folder on the current folder.

"Img/a.gif" refers to D: \ myweb \ mypic \ IMG \ a.gif. "img/" indicates the IMG folder under the current folder.

The relative path of a document is the simplest path. Generally, it is used to link documents stored in the same folder.

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.