Relative vs. absolute links
A hyperlink that points to a Web document or resource may use either a relative URL or an absolute URL. The distinction has to do with how complete, or self-sufficient, the pathA path is a description of the location within the folder structure of a Web site (or the local file system). pointing to the destination is.
Relative URLs
A relative URL consists of just a path that contains only enough information to locate a file in relation to the location of the document containing the URL. Using a relative link is like using your company’s internal mail system. If you need to send a memo to someone in your own department, you can just address it to the person’s name, such as “Betty Jones” (assuming there is just one Betty Jones in your department). To reach someone in another department, it might be sufficient to use the department name plus the person’s name; for example, “Marketing/Betty Jones”. You don’t have to specify a street address, city, state, ZIP code, and so forth, since the company mail system assumes that an address that doesn’t have these parts must refer to someone inside the company.
Similarly, a relative URL only needs to provide a file name, or a file name plus a directory path. The Web browser (or Namo WebEditor) assumes that such a URL must point to a file in the folder structure of the same site as the containing document, and it interprets the URL accordingly.
Here are some examples of relative URLs:
Relative URL |
File Location |
---|---|
example.html |
the same folder as the document |
images/example.gif |
the “images” subfolder of the document’s folder |
images/photos/alice.jpg |
the “photos” subfolder of the “images” subfolder of the document’s folder |
../index.html |
the parent folder of the document’s folder |
../../example.css |
the parent folder of the parent folder of the document’s folder |
Absolute URLs
Unlike a relative URL, an absolute URL does not depend on the location of the document containing it. To continue the analogy given above, using an abolute link is like mailing a letter with a full name and address through the national post. The name and address should uniquely identify the intended recipient, without ambiguity and without reference to the location of the sender.
Whereas relative URLs are always local (they always point to resources on the same site as the document containing the link), absolute URLs can be either local or global—they can point to resources anywhere on the Web.
A local absolute URL consists of just an absolute path to the resource. It starts with a slash (“/”), indicating that the path starts at the root (or top) level of the Web site’s folder hierarchy. Since the path starts at the root, it always points to the same file, regardless of where in the site’s folder structure the document containing the link is.
Here are some examples of local absolute URLs:
- /index.html
- /images/example.gif
- /products/webeditor/tour/tour1.asp
A global absolute URL—also called a full URL—is one that provides not just an absolute path, but also a site address. Thus, a global URL can point to a unique resource anywhere on the Internet. A global URL must start with the name of the protocol used to connect to the destination (such as “http:”) followed by a double slash (“//”), the site address, and then the resource path. (If the resource path is not specified, the URL points to the root of the site, which may be represented by an index page at the root level.)
Here are some examples of global absolute URLs:
- http://www.example.com/products/index.html
- http://www.example.com/
- ftp://ftp.namo.com
- ftp://ftp.namo.com/public/webeditor_demo.exe
Notice that the second and third examples do not provide a path. In the case of the HTTP URL, the Web server will probably serve up the index page in the root folderThe “home” or top-level folder of a local or remote site; the folder that contains the site’s home page or main index file. A root folder may contain subfolders in addition to documents. of the site. In the FTP case, the FTP server will provide a listing of the server’s root directory.