The difference between absolute path and relative path in Web page making

Source: Internet
Author: User
Tags file info joins

The difference between absolute path and relative path in Web page making http://www.veryhuo.com fire net 2012-10-10deliver manuscriptTo be a developer, the definition of a file or a folder is a certain standard, such as the establishment of a website front-end design, the folder to be established css,js,images,swf and so on,

Many files under a single page connection, file references need to have a certain understanding of the path problem, or the PHP network program development has a knowledge of programmers will define and include to define variable paths and references have a lot of insight.

Like what:

Define (' Root_path ', DirName (__file__));
Include (Root_path. " /inc/webconfig.php ");
Include (Root_path. " /inc/sysinfo.php ");
Include (Root_path. " /inc/functions.php ");
Include (Root_path. " /inc/db_sql.php ");

These are all I have to analyze.

Main content:

    • The concept of relative paths and absolute paths
    • Specific analysis

The concept of relative paths and absolute paths

In the operating system class, this is said, in the file lookup, absolute path: In the tree directory structure, from the root node to the person a data file or directory files have only one path. The name of each directory and the data file name that passes through the path from the root node to a data file are concatenated with "/" to form a pathname that can be used to access the data file; relative path: You can set a "current directory" for each process, also known as the "working directory", This way, each time you find a file, you do not need to use the absolute path mechanically, and instead use the path relative to the current directory, which is the relative path. Of course, it's a little abstract, specifically see below my analysis of the main application in HTML

Specific analysis

HTML beginners often encounter such a problem, how to correctly reference a file. For example, how do you refer to another HTML page as a hyperlink (hyperlink) in an HTML page? How do I insert a picture in a Web page?

If you use the wrong file path when referencing a file (such as adding a hyperlink, or inserting a picture, etc.), it will invalidate the reference (the linked file cannot be browsed, the inserted picture cannot be displayed, etc.).

To avoid these errors and to properly reference the file, we need to learn the HTML path.

HTML has 2 ways of writing: relative and absolute paths.

HTML relative path (Relative path) file reference for the same directory

If the source and reference files are in the same directory, write the reference file name directly.

We are now building a source file info.html, in info.html to refer to the index.html file as a hyperlink.

Suppose the info.html path is: c:\Inetpub\wwwroot\sites\blabla\info.html assumes the index.html path is: c:\Inetpub\wwwroot\sites\blabla\ Index.html the code that joins the index.html hyperlink in info.html should be written like this:

How to represent a parent directory

.. /represents the top level directory of the directory where the source file resides, http://www.cnblogs.com/represents the upper parent directory of the directory where the source file resides, and so on.

Suppose the info.html path is: c:\Inetpub\wwwroot\sites\blabla\info.html assumes the index.html path is: c:\Inetpub\wwwroot\sites\index.html The code that joins the index.html hyperlink in info.html should be written like this:

Suppose the info.html path is: c:\Inetpub\wwwroot\sites\blabla\info.html assumes the index.html path is: c:\Inetpub\wwwroot\index.html The code that joins the index.html hyperlink in info.html should be written like this:

<a href = "http://www.cnblogs.com/index.html" >index.html</a>

Suppose the info.html path is: c:\Inetpub\wwwroot\sites\blabla\info.html assumes the index.html path is: c:\Inetpub\wwwroot\sites\wowstory\ Index.html the code that joins the index.html hyperlink in info.html should be written like this:

<a href = ". /wowstory/index.html ">index.html</a>
How to represent a subordinate directory

Refer to the Subordinate directory file, directly write the path of the subordinate directory file.

Suppose the info.html path is: c:\Inetpub\wwwroot\sites\blabla\info.html assumes the index.html path is: c:\Inetpub\wwwroot\sites\blabla\html\ Index.html the code that joins the index.html hyperlink in info.html should be written like this:

<a href = "html/index.html" >index.html</a>

Suppose the info.html path is: c:\Inetpub\wwwroot\sites\blabla\info.html assumes the index.html path is: c:\Inetpub\wwwroot\sites\blabla\html\ Tutorials\index.html the code that joins the index.html hyperlink in info.html should be written like this:

<a href = "html/tutorials/index.html" >index.html</a>
HTML absolute Path (Absolute path)

The HTML absolute Path (absolute path) refers to the full path of the file with the domain name.

Suppose you register the domain name www.abc.com, and apply for a virtual host, your virtual hosting provider to you a directory, such as WWW, this www is the root directory of your site.

Suppose you have a file index.html in the WWW root directory, the absolute path to this file is: http://www.abc.com/index.html.

Suppose you build a directory under the WWW root called html_tutorials, and then drop a file in the directory index.html, the absolute path to this file is http://www.abc.com/html_tutorials/index.html.

The difference between absolute path and relative path in Web page making

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.