HTML relative path and absolute path

Source: Internet
Author: User
Tags file info joins parent directory relative root directory

If you use the wrong file path when referencing a file (such as adding a hyperlink, or inserting a picture, etc.), you can invalidate the reference (you cannot browse the linked file, or you cannot display the inserted picture, and so on).
To avoid these errors, and to refer to the file correctly, we need to learn the HTML path.
HTML has 2 ways of writing: A relative path and an absolute path.
HTML relative path (relative path)
File references for the same directory
If the source file and reference file are in the same directory, write the reference file name directly.
We now build a source file info.html, in info.html to reference index.html file as a hyperlink.
Suppose the info.html path is: c:inetpubwwwrootsitesblablainfo.html
Suppose the index.html path is: c:inetpubwwwrootsitesblablaindex.html
The code that joins the index.html hyperlink in info.html should write this:

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

How to represent a parent directory
.. /indicates the directory in which the source file is located, ... /.. /represents the parent directory on the directory where the source file resides, and so on.
Suppose the info.html path is: c:inetpubwwwrootsitesblablainfo.html
Suppose the index.html path is: c:inetpubwwwrootsitesindex.html
The code that joins the index.html hyperlink in info.html should write this:

<a href = "L" >index.html</a>
Suppose the info.html path is: c:inetpubwwwrootsitesblablainfo.html
Suppose the index.html path is: c:inetpubwwwrootindex.html
The code that joins the index.html hyperlink in info.html should write this:

<a href = "L" >index.html</a>
Suppose the info.html path is: c:inetpubwwwrootsitesblablainfo.html
Suppose the index.html path is: c:inetpubwwwrootsiteswowstoryindex.html
The code that joins the index.html hyperlink in info.html should write this:

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

How to represent a subordinate directory
A file that refers to a subordinate directory, directly to the path of the subordinate directory file.
Suppose the info.html path is: c:inetpubwwwrootsitesblablainfo.html
Suppose the index.html path is: c:inetpubwwwrootsitesblablahtmlindex.html
The code that joins the index.html hyperlink in info.html should write this:
<a href = "html/index.html" >index.html</a>
Suppose the info.html path is: c:inetpubwwwrootsitesblablainfo.html
Suppose the index.html path is: c:inetpubwwwrootsitesblablahtmltutorialsindex.html
The code that joins the index.html hyperlink in info.html should write this:

<a href = "html/tutorials/index.html" >index.html</a> 
HTML absolute Path (absolute path)
HTML absolute Path ( Absolute path refers to the full path of a file with a domain name.
Suppose you register a domain name/html and apply for a virtual host, your hosting provider gives you a directory, such as WWW, which is the root directory of your site.
Assuming that you have a file index.html in the WWW root directory, the absolute path to this file is:.
Suppose you have built a directory called Html_tutorials in the WWW root directory, and then placed a file index.html in the directory, the absolute path of this file is/html_tutorials/index.html.  

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.