Skip Navigation

Web FAQs

Tags: General HTML
File Author Send email Website
998810374 Ronx to Ronx www.rxs-enterprises.org
 

Relative and Absolute Addressing

This shows the differences between absolute, virtual and relative addressing


Absolutely Relative Addressing

First, some definitions:

Server Root folder: The top level directory the server looks at. In IIS servers this is usually c:\inetpub\wwwroot; in Apache servers (running on windows) the default is c:\program files\apache\hdocs . In both cases the administrator can move the root to wherever is more suitable on the machine.
Site Root folder: The top level directory in your site. In IIS this is usually the server root or a sub directory off the server root. In a Unix environment the path may be similar to (but not exactly like) c:/apache/users/example/pub

This tutorial will use two web sites:

  • Site 1 is www.rxs-enterprises.org
  • Site 2 is www.example.com/~rxs.enterprise/

Note that site 2 does not exist in real life, but represents a site using space "donated" by an ISP.

Up to a point both sites have the same file and directory structure. This short tutorial will consider the location of three files on each of these sites, using three different methods of referencing them.

The files are named index.html, privacy.html, and blorulec.gif located in each sites' root, mainpage, and images directories respectively.

1-Absolute Addressing

Absolute addressing specifies not only the location on the server, but the server itself. Notice that the addresses are unique to the servers, and are not portable. Absolute addresses also include the protocol in use. (for example, ftp://example.com/ may be a different server to http://example.com , or a different folder on the same server [just to confuse])
Use Absolute Addressing to link to other sites.

Site 1 http://www.rxs-enterprises.org/index.html
http://www.rxs-enterprises.org/mainpage/privacy.html
http://www.rxs-enterprises.org/images/blorulec.gif
Site 2 http://www.example.com/~rxs.enterprise/index.html
http://www.example.com/~rxs.enterprise/mainpage/privacy.html
http://www.example.com/~rxs.enterprise/images/blorulec.gif

2-Relative Addressing

(This example is relative to the site's root directory)

This mode of addressing is portable - it will work at any location on any server.
Use relative addressing to link to pages and files within your web site.

Site 1 Site 2
index.html index.html
mainpage/privacy.html mainpage/privacy.html
images/blorulec.gif images/blorulec.gif

3-Relative Addressing

(relative to mainpage directory)

This is the same as above, but from a different starting point - again totally portable

Site 1 Site 2
../index.html ../index.html
privacy.html privacy.html
../images/blorulec.gif ../images/blorulec.gif

Note how the ../ goes up one directory level, similarly ../../ will go up two levels, and so on. In effect, climb up the directory tree using ../ as rungs on a ladder, and slide down using directory names.

Exercise 1

On page www.rxs-enterprises.org/CountryCodeDecoder/default.aspx there is a line:

<script type="text/javascript" src="../_themes/rxsprogs.js"></script>

What is the absolute address for the .js file?
Using the same .js file, what is its relative address on the page
www.rxs-enterprises.org/mainpage/privacy.html
(Answers at the bottom of this page)

4-Relative Addressing

(relative to server Root)

This method of relative addressing is similar to the previous method - except the starting point is specified as the server root. This method of addressing is only portable if you have your own server (or virtual server) and you are are porting to a similar setup. If sharing a server, as with BT Internet, Freeserve and most other ISPs (as opposed to Hosts or WPPs ) the method is not portable. Addressing method 2 is often easier, but if the server root is the site root, this method eases the strain of wading through multiple levels of ../

Site 1 Site 2
/index.html /~rxs.enterprise/index.html
/mainpage/privacy.html /~rxs.enterprise/mainpage/privacy.html
/images/blorulec.gif /~rxs.enterprise/images/blorulec.html

The expression /~rxs.enterprise/mainpage/privacy.html may not operate correctly. BT Internet, for example, seems to use many levels of hardware and software URL aliasing and redirection, and working relative to the server root may lead to unexpected results

Exercise 2

What is the address relative to the server root for that .js file that goes on the same page in exercise 1?
Answer at the bottom

Answers

Exercise 1
absolute: http://www.rxs-enterprises.org/_themes/rxsprogs.js
relative: ../_themes/rxsprogs.js (relative to the mainpage directory)
Exercise 2
relative to server root /_themes/rxsprogs.js