ptg16476052
Linking Local Pages Using Relative and Absolute Pathnames 97
6
the top level of your directory hierarchy and working downward through all the interven-
ing directories to reach the file.
Absolute pathnames always begin with a slash, which is the way they’re differentiated
from relative pathnames. Following the slash are all directories in the path from the top
level to the file you are linking.
Top has different meanings, depending on how you’re publishing
your HTML files. If you’re just linking to files on your local disk,
the top is the top of your file system (/ on UNIX, or the disk name
on a Macintosh or PC). When you’re publishing files using a web
server, the top is the directory where the files served by the web
server are stored, commonly referred to as the document root.
NOTE
Table 6.2 shows some examples of absolute pathnames on a local computer and what
they mean.
TABLE 6.2 Absolute Pathnames Examples
Pathname Means
href=”/home/lemay/file.html” file.html is located in the directory /home/lemay
(typically on UNIX systems).
href=”/d|/files/html/file.htm” file.htm is located on the D: disk in the directory
files/html (on Windows systems).
href=”/Macintosh%20HD/
HTML%20Files/file.html”
file.html is located on the disk Macintosh HD, in
the folder HTML Files (typically on OS X systems).
In the last example, the series of characters “%20” represents a space. It has been
encoded so that the space character does not cause issues. You’ll learn more about this
encoding later on.
Should You Use Relative or Absolute Pathnames?
The answer to that question is, “It depends.” If you have a set of files that link only to
other files within that set, using relative pathnames makes sense. On the other hand, if the
links in your files point to files that aren’t within the same hierarchy, you probably want
to use absolute links. Generally, a mix of the two types of links makes the most sense for
complex sites.