Absolute and Relative Path Names


If you have numerous web document files and have created sub-directories to organize your files, it is essential that you understand the difference between Absolute and Realtive path names for your links. Below are definitions and examples of each.

Most of the time, use relative path names when you link to files in the same UNIX account or drive for a good reason


Terms

Links The hypertext or hypermedia element on web pages that permits you to jump to another location or file
Local Files (documents) --Files that are in your UNIX account
Remote Files (documents) --Files that are not in your UNIX account, but at a remote location
Absolute path names
(Use absolute path names to link to remote files.)
  • Links to a file with its full pathname
  • Begins with a slash ( / )
  • Example: <A HREF "/~jack/virus/virus.html">
Relative path name
(Use relative path names to link to local files.)
  • Links to a local file, relative to the location of current page that you are on
  • Begins with a filename or 2-dots with a slash or ( ../ ) or a directory name proceeded the filename
  • Example: <A HREF "virus.html"> or <A HREF "../virus.html"> or <A HREF "virus/virus.html"

Examples:

The following table compares the absolute and the relative path names for a web page that describes our PC Lab. The filename, in my UNIX directory, is:
pc_intro.html
The URL for this file is:
http://www.towson.edu/~jack/lab/pclab/pc_intro.html

Absolute Path Names

Absolute Path Name Description
<A HREF="/~jack/lab/pclab/pc_intro.html"> The file pc_intro.html is located in the
/pclab sub-directory, which is in the
/lab sub-directory of my
home directory jack
Note: directories in UNIX are seperated by a forward slash ( / )
<A HREF="/C:/HTML/pc_intro.html"> The file pc_intro.html is located in HTML directory on the C: hard drive
<A HREF="Hard Disk 1/HTML Folder/pc_intro.html"> On a Macintosh:
The file pc_intro.html is located in HTML folder of Hard Disk 1














Realtive Path Names

Relative paths are relative to the file you are currently in.

Relative Path Name Description
<A HREF="lab/pclab/pc_intro.html">
(I am in my home directory here)
The file pc_intro.html is located 2 directories below the directory I am in
/pclab sub-directory, which is in the
/lab sub-directory of my
home directory jack
Note: directories in UNIX are seperated by a forward slash ( / )
<A HREF="../../tsu.gif"> The file tsu.gif is located 2 directories above the directory I am in
<A HREF="../tsu.gif">
The file tsu.gif is located 1 directory above the directory I am in
<A HREF="/C:/HTML/pc_intro.html"> The file pc_intro.html is located in HTML directory on the C: hard drive
<A HREF="Hard Disk 1/HTML Folder/pc_intro.html"> On a Macintosh:
The file pc_intro.html is located in HTML folder of Hard Disk 1
















Above information adapted from Laura Lemay's book: "Web Publishing with HTML." I recommend this book for basic HTML publishing.


E-mail: jack@towson.edu


Last Modified: 7/21/97