Base URL for CD-ROM distribution (absolute and relative paths)

Top  Previous  Next

Understanding absolute and relative paths are important to determine the most consistent and effective way of linking to files, and it is useful knowledge to all web developers.

The following is a brief explanation for those who are not yet familiar with these forms of file paths, which are especially necessary for defining the base URL for CD-ROM and offline distribution.

Absolute paths

Absolute paths refer to specific locations, independent of the current location of the file. These usually begin with a “/” or even the domain of the site (eg. “http://mysite.com/”). When a path begins with a “/”, this is a reference to the root directory.

For instance, if you have the following files:

absolute_path_ex1

Now assuming you have your search files in the search folder, and you need to link to a file in the articles folder. An absolute link would be “/MyCD/articles/page1.html”. Note that this link refers to the location of the file from the root directory, and thus it will refer to the same file regardless of where you place this link.

However, when you copy the contents of the “MyCD” folder to your CD-ROM, it may now look something like this:

absolute_path_ex2

As you can see, a reference to “/MyCD/articles/page1.html” would no longer be valid. The link would now have to be “/articles/page1.html”.

Because of this issue, we generally recommend against using absolute paths if you intend to publish your files on a CD-ROM. It also causes similar issues to those described above on different Operating Systems, such as the Mac, which refers to the CD drive as a part of the path (eg: the path would be “/cdrom/articles/page1.html”).

Relative paths

Relative paths refer to file locations based on the current directory. That is, they often refer to locations in the form of “up one directory level” and often begin with one or two dots (“.”). An example would be “../index.html” which would refer to the file “index.html” one directory level up.

A key to relative paths:

A single dot (“.”) refers to the current directory, eg. “./test.html” would refer to the file “test.html” in the current directory.
Double dots (“..”) refer to the previous directory, eg. “../test.html” would refer to the file “test.html” in the previous directory.
To refer to a location which is more than one directory level up, use a combination of double dots, eg. “../../test.html” would refer to a file two directory levels up.

In the case of the illustrated example above (for absolute paths), you would link to the same file with a relative path of “../articles/page1.html”. This would then still be correct when your files are moved off to a CD-ROM, because the articles folder  is always one level up from the search folder.

What should I use as the base URL for a CD or DVD?

If you need your search files to run on a CD-ROM (this also assumes you are using the Javascript version), in most cases, a base URL of “./” would work. This assumes that your search files will be located in the root directory of your CD.

If however, you host your search files on a subdirectory, eg. a “search” folder off the root directory of the CD, then you would need a base URL of “../” to refer to the linked files. Refer to the above section on relative paths for more information on determining the correct relative path.