Directories And URLs

What Is A Directory?
A directory is a Linux file that contains other files. The files housed in a directory can be of any type, including other directories. Directories can be thought of as file cabinets or file folders and are usually represented as such on graphical desktops.

The "root" Directory
The root directory is the master directory that contains all the other directories. Just as the "root" user is the ultimate authority in users, the root directory is the source of all other directories. The root directory is represented as "/" and forms the main trunk of the directory tree.

Parent Directories
A "parent directory" is a directory holding one or more subdirectories. The illustration shows that the /usr directory is a parent directory coming directly off of the root directory. Parent directories form the major branches of the directory tree.

Subdirectories
Subdirectories are directories that exist within another directory. A directory can be both a parent and a subdirectory. In the case of "/etc/sendmail/" "/etc" is the parent directory of the "/sendmail" subdirectory in addition to being as a subdirectory of root. Subdirectories form the minor branches of the directory tree.



When you log in, you are automatically placed in a directory with a path that looks like:


Inside of there is a directory called htdocs, so its path is:


The web server (Apache) is gonna look in there for a file called "index.htm":



You can have subdirectories inside of htdocs/ and link to files in them:



You can also link to pages inside of subdirectories:



If you have a file called "index.htm" inside of a subdirectory it can be called like this:




URLs
URL stands for Universal Resource Locator. They are also refered to as links or hyperlinks.

There are two ways to link to other files: with either absolute or relative URLs. An absolute URL includes the full Web address and looks like this:

<A HREF="http://www.domainname.com/pages/page.htm">

If you're linking to files on your own site, however, you need to specify only the pathname relative to the current document. In the above example, when creating a link from the home page to page.htm, you need to use only the following:

<A HREF="pages/page.htm">

To link from page.htm back to the home page (at index.htm), use this:

<A HREF="../index.htm">

The dots and slashes work just like DOS CD commands, except the slashes go in the other direction. For instance, to move up three directories and then down into the Words directory, use this:

<A HREF="../../../pages/page.htm">

Relative URLs have two advantages over absolutes. First, users connect to them faster, because a DNS router doesn't have to look up the host every time. Second, because relative URLs invoke a directory architecture instead of host names, you can view and test such sites from a copy of the site on your hard disk or a network drive. This portability is especially welcome if you ever move your entire site to a different host server.


Note:
Our web servers run Apache on Linux and are very case sensitive. So if the html refers to a file called image.GIF, but it is actually name image.gif, then Apache won't be able to find it.