Basic HTML directory problem (difference between relative path and absolute path)

Basic HTML directory problem (difference between relative path and absolute path)
Relative path - a directory path established based on the location of the web page that references the file. Therefore, when web pages saved in different directories reference the same file, the paths used will be different, so it is called relative.
Absolute path - a directory path based on the root directory of the Web site. It is called absolute because when all web pages reference the same file, the path used is the same.
In fact, the difference between an absolute path and a relative path is only that different reference points are used when describing the directory path. Since the root directory is the same reference point for all files on the website, the path description method using the root directory as a reference point is called an absolute path.
The following are several special symbols used to establish paths and their meanings.
"."--represents the current directory.
".."--represents the upper directory.
"/"--represents the root directory.
Next, we assume that the website created by the reader has the directory path shown in the following figure.

If you want to reference the BeRef.gif file in the Ref.htm file, the relative path is as follows:

./SubDir2/BeRef.gif

In the reference path above, "." represents the current directory (Dir1), so "./SubDir2" represents SubDir2 in the current directory. In fact, you can also omit "./" and directly use this method to quote.

SubDir2/BeRef.gif

If you use an absolute path to reference the file with the root directory as the reference point, the reference path is as follows:

/Dir1/SubDir2/BeRef.gif

If the directory structure of the Web site is as shown below

What about the relative path of the BeRef.gif file?

If you want to reference the BeRef.gif file in the Ref.htm file, its relative path is as follows:

../SubDir2/BeRef.gif

In the reference path above, ".." represents the parent directory, so "/Dir2" represents the Dir2 subdirectory under the parent directory. If an absolute path is used for reference, the reference path is as follows:

/Dir2/BeRer.gif

Let's take a more complicated example to compare the use of relative paths and absolute paths. Assume that the website you created has the directory path as shown in the figure below.


We use a table to illustrate the relative path and absolute path that should be used when a file references another file in the above situation.

Cited by
Cited by
Relative Path
Absolute path
Ref1.htm BeRef1.gif ../SubDir2/BeRef1.gif /Dir1/SubDir2/BeRef1.gif
Ref2.htm BeRef1.gif ../../Dir1/SubDir2/ BeRef1.gif /Dir1/SubDir2/ BeRef1.gif
Ref1.htm BeRef2.htm ../../Dir2/ BeRef2.htm /Dir2/BeRef2.htm
Ref2.htm BeRef2.htm ../BeRef2.htm /Dir2/BeRef2.htm

What needs to be explained in the above table is the meaning of "../../".

".." represents the parent directory, and "../../" represents the parent directory of the parent directory. Therefore, as can be seen from the above table, if the referenced file exists in a subdirectory of the current directory, or in another subdirectory of the upper directory, it is more convenient to use a relative path. If not, just use the absolute path, which is more convenient. From the above table, we can also see that when the same file is referenced, the absolute path used to reference the file is the same.

<<:  Detailed use cases of vue3 teleport

>>:  How to connect Navicat to the docker database on the server

Recommend

How to add Lua module to Nginx

Install lua wget http://luajit.org/download/LuaJI...

Achieve 3D flip effect with pure CSS3 in a few simple steps

As a required course for front-end developers, CS...

How to quickly install RabbitMQ in Docker

1. Get the image #Specify the version that includ...

A Brief Analysis of MySQL - MVCC

Version Chain In InnoDB engine tables, there are ...

Detailed steps for setting up and configuring nis domain services on Centos8

Table of contents Introduction to NIS Network env...

How to deploy hbase using docker

Standalone hbase, let’s talk about it first. Inst...

How to build SFTP server and image server on Linux cloud server

First of all, you can understand the difference b...

Practice using Golang to play with Docker API

Table of contents Installing the SDK Managing loc...

36 principles of MySQL database development (summary)

Preface These principles are summarized from actu...

CentOS installation mysql5.7 detailed tutorial

This article shares the detailed steps of install...

Some suggestions for Linux system optimization (kernel optimization)

Disable swap If the server is running a database ...

A detailed discussion of MySQL deadlock and logs

Recently, several data anomalies have occurred in...

Docker learning method steps to build ActiveMQ message service

Preface ActiveMQ is the most popular and powerful...