ABSOLUTE versus RELATIVE urls - definition

Gaile

Joined: 2002-07-20
Posts: 1301
Posted: Thu, 2005-05-26 23:22

As there seems to still be confusion about the difference between relative and absolute urls, I thought I'd post a little information and a reference link for everyone.

URL is just a fancy name for "address". You use an "url" to give the address to a link or image.

An url that is ABSOLUTE shows the complete address. In other words, there is no confusion about where this item is located, as the ABSOLUTE URL gives the entire path to that file. http :// mysite.com/ images/me.jpg is an example of an ABSOLUTE url.

A url that is RELATIVE only shows a partial address - like images/me.jpg - and the success or failure of finding the file is contingent on certain conditions being met - which means the outcome can and will vary, depending largely how how the directories within your website are structured.

EXCELLENT REFERENCE: URLS explained. Read it once and you'll always remember the difference between an absolute and relative reference.

For the purposes of G1 - always use ABSOLUTE urls when referencing images and links and you'll avoid the dreaded RED X so many people have problems with.

Gaile

 
mbuna
mbuna's picture

Joined: 2002-12-26
Posts: 96
Posted: Mon, 2006-02-13 15:43

Further explanation.

In a relative URL if you start with a / as in /images/me.jpg this will start looking for the directory at the root of your sites file structure. This also translates into the root of the domain. IE: http: //mydomain.com /images/me.jpg

So if your sites root directory is /htdocs/mysite a relative URL of /images/me.jpg translates to /htdocs/mysite/images/me.jpg

However if you leave off the leading / this starts the relative URL at the directory you are in.

So if you are at http:// mydomain.com/gallery/album1 a relative url of images/me.jpg translates into http:// mydomain.com/gallery/album1/images/me.jpg

Sean
http://www.Aquaria.info
http://www.FishBanners.com
http://www.TopPetSites.com
http://www.CleanLiving.com
http://www.DigFishDig.com