Re: root urls- Absolute and relative referencing

by "Thomas Bradley" <thombrad(at)visi.net>

 Date:  Sun, 01 Oct 2000 18:52:51 -0400
 To:  "Lady Wistfulee" <wistfulee(at)millenicom.com>,
hwg-techniques(at)hwg.org
 References:  0020017605
  todo: View Thread, Original
	What you have there is 2 different examples of relative URL's. This can be=
 a rather confusing topic so, I will go back and describe the entire topic=
 of relative and absolute URL's. I have created the directory structure in=
 the example here as a reference. Please excuse me if you cannot receive=
 HTML. I am trying to describe a domain with a structure of index.html,=
 picture.jpg and graphic.gif in the root, a folder containing 2 files and a=
 2 folders.  One is called called objectsfolder which contains  object1,2=
 and a file page#4.html. The second folder is called Scriptsfolder and=
 contains the file script#1.js.
<pre>
 	www.mydomain.com
		|
		|
	       index.html
	       picture.jpg
	       graphic.gif
		|	
		|___foldernumber1
			|
			|	
		      page#2.html
		      page#3.html
			|
			|__Objectsfolder
			|	|
			|      object#1.jpg
			|      object#2.js
			|       page#4.html 
			|
			|__scriptsfolder
			            |
			       script#1.js

</pre>
			

	There are 2 types or references for links and anchors, absolute and=
 relative. 
Absolute references- use the root of the domain as the basis for beginning=
 the referencing a documentand use the entire URL. 
Relative references- use the position of the current document in the=
 directory tree to describe the position of the documnet.

Say we are coding the file page#4.html in the previous tree and need to=
 reference the object#1.jpg in the same folder.
To use Absolute reference we would describe the position as:

<a href=3D "www.mydomain.com/foldernumber1/Objectsfolder/object#1.jpg">=
 </a>

Absolute reference always uses the entire address. You always use this to=
 refer to documents in other domains.

There is a similar way to describe this relatively that can be used if the=
 file is in your own domain. If you describe the link by giving it's=
 position to the root directory of the domain. Sometimes referred to as=
 root relative, you begin the description with a "/". To find the=
 object#1.jpg file from any place in the directory do it this way:

<a href=3D "/Objectsfolder/object#1.jpg"> </a>

There are 2 different ways to move about using relative references.
If the file you wish to reference is in the same directory, no mapping=
 references need be used. If you are coding page#4.html 
 and need to reference object#1.jpg you could reference is directly thus:

<a href=3D "object#1.jpg"> </a>

The last is similar to moving around in DOS. You use two periods and a=
 forwad slash ("../") to move up 1 directory then name the directory name=
 for each folder you need to move down. For example, to code page #4.html=
 to reference  script#1.js you would code it thus:

<a href=3D "../scriptsfolder/script#1.js"> </a>

to reference graphic.gif
<a href=3D "../../graphic.gif"> </a>


To summarize:
Absolute- www.mydomain.com/foldernumber1/Objectsfolder/object#1.jpg

Relative "/" brings you back to root>
	"../" moves you up 1 directory
nothing is required if the file is in the same directory.

Sorry for the long post but this is a topic that repeatedly comes up in=
 classes I attend and I found it easier to go the whole route.

Thom Bradley
Thinking, sometimes I like to listen to the sound of my own typing?





 



 
*********** REPLY SEPARATOR  ***********

On 10/1/00 at 4:41 PM Lady Wistfulee wrote:

>Hello O Web Gurus,
>
>I was informed at work this week that by adding a forward slash in my URL
>path, it would automatically revert the URL to the root domain...instead=
 of
>using "<.a href=3D" ../folder/file.ext> "  I should use " <.a
>href=3D"/folder/file.ext> ".
>I was told that this works in all browsers, but it was not what I was
>taught...so if someone could please give me an authoritative answer on=
 this,
>I would greatly appreciate it.
>
>much alohas,
>Lady Wistfulee
>"Light travels faster than sound. This is why some people appear bright
>until
>you hear them speak."

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA

This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.