Relative vs. Absolute Addresses

There are two primary ways of configuring hyperlinks which are based on what relationship the documents being linked have to the document which contains the links. If the documents are part of a collection of HTML pages which are all located on the same web site at the same server, they can be addressed Relative to each other. If the document being linked resides at a different web site or on a different server, then the link which points to that document must contain an Absolute address. Absolute addresses are also sometimes referred to as Fully Qualified addresses.

The following graphic illustrates a collection of directories (which is what "folders" are called when they're not on a Macintosh). These directories reside on an imaginary computer we'll call server.name.net.

Working Directory

You will notice that the directory which is open in the graphic is called Web_Site. If the server was running Unix or a system like it, the directory's name would be /Web_Site. For the sake of this explanation, we will assume that the document we are working with is the document named index.html which is contained within the Web_Site directory. The fact that /Web_Site contains the documents we are currently working with makes it the Working Directory. The directory /Web_Site is the Child Directory of the directory called /Directory1, which is known as the Parent Directory. What this graphic depicts is frequently called a Directory Tree. You will notice that the directory /Garbage is on the same Branch of the tree as the directory /Web_Site. Other branches of the tree include those containing the directories named /Directory2 and /Directory3.

If we were putting a link in the document index.html which referenced the document evil.html, which also resides in the working directory, we could use either a Relative Address which would indicate its location relative to index.html, or we could use a Absolute Address which would indicate its location relative to the server, server.name.net. If the link was going in the document index.html, the Relative Address would be simply evil.html, and the Absolute Address would be

http://server.name.net/DirectoryA/Directory1/Web_Site/evil.html.

This is made even more confusing when we start talking about relative addresses for documents which are not contained within the working directory.

The /Garbage child directory

The graphic shows documents located in the /Garbage directory, which is another child directory of /Directory1. In order to reference a document which is not contained within the working directory, we must first "move" out of the working directory, into its parent directory, and then specify the path to the new document. To move from the working directory to its parent directory use the ../ direction. This moves the focus from the working directory to its parent directory. If the document we were targeting was located in the parent directory, we could add the document name after the ../ direction and have the relative address of that document. Because of the fact that the document we are targeting is located in the /Garbage directory, we need to add the directory name to the relative address. So, if we were creating a link from /Web_Site/index.html to /Garbage/slobber.html, the relative address would look like this, ../Garbage/slobber.html, and the absolute address would look like this,

http://server.name.net/DirectoryA/Directory1/Garbage/slobber.html

If we wanted to create a link to a document which is located in the /DirectoryB directory, we would have to move to the parent directory of /Directory1 in the same way we moved to the previous parent directory. The direction to move to the parent directory ../ can be repeated as many times as necessary.

In order to insure that relative addresses resolve to the correct absolute address, a <BASE> tag can be used, with a href attribute which indicates the location of the document which contains it. The <BASE> tag goes in the head section of the document. If we were adding a <BASE> tag to the document we were working with earlier ( /Web_Site/index.html ) it would look like this:

<BASE HREF="http://server.name.net/DirectoryA/Directory1/Web_Site/index.html">

This <BASE> tag instructs the browser how to resolve relative addresses and gives an indication of the location of documents which are linked, relative to the document which contains the <BASE> tag.

When linking to documents which reside outside of the directory tree, whether on a virtual host on the same machine, or on a machine other than the one which contains the document being authored, the link must contain an absolute address. There is no way of using a relative address to link such a document, because there would be no way to know the name of the server on which the target document was located.